-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Flexbox story sidebar #9532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Flexbox story sidebar #9532
Changes from all commits
788003f
0655630
ad97de8
7cedc8c
04f6a32
f4c3496
0449b7d
f052b2d
9c32080
bc2106e
fb00b69
d5513ba
b43d26c
ec14a79
ddf6062
0852590
9c188d8
d39a142
f558c5f
75427e6
62c2b3e
ce7df68
7ee54ae
32b06fd
a6a527a
e21ec97
284c481
766ef2d
5ba4c9f
94b3e13
e912813
96b2dd7
bb66a37
f0c453e
68063ee
e2779b2
4712ea9
4cb84e2
ac1462e
4c5b669
daf6f72
ab8037f
469b93c
1e8f31b
fa2fc08
5b45b1f
6227bfa
2b9f838
d1e74d5
1122153
e5e3f68
33f0a14
759d915
6220203
85124e3
2695629
81a2c04
bcff1b7
cf34eaf
fe435b7
f8bccd9
1177d7c
6bb9068
b617ea9
ba06506
ff30566
ae2fb0b
bc0966a
dec2a90
5f5b9aa
a3ba6e6
72d7960
fb56dc2
7a16901
7bf6d54
cd20b61
8e527e5
873cb2c
11e65fb
bf6331e
ec0ea1a
493dfe1
a517c9a
816fd5b
98d100d
c1b706d
0ecddfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| title: $:/language/BottomToolbar/ | ||
|
|
||
| Hint: Bottom toolbar | ||
| Back/Caption: Back | ||
| Back/Hint: Go back | ||
| Home/Caption: Home | ||
| Home/Hint: Go to start | ||
| New/Caption: New | ||
| New/Hint: Create new tiddler | ||
| Search/Caption: Search | ||
| Search/Hint: Open search | ||
| Menu/Caption: Menu | ||
| Menu/Hint: Toggle sidebar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /*\ | ||
| title: $:/core/modules/background-actions.js | ||
| type: application/javascript | ||
| module-type: global | ||
|
|
||
| Class to dispatch actions when filters change | ||
|
|
||
| \*/ | ||
|
|
||
| "use strict"; | ||
|
|
||
| class BackgroundActionDispatcher { | ||
| constructor(filterTracker, wiki) { | ||
| this.filterTracker = filterTracker; | ||
| this.wiki = wiki; | ||
| this.nextTrackedFilterId = 1; | ||
| this.trackedFilters = new Map(); // Use Map for better key management | ||
| // Track the filter for the background actions | ||
| this.filterTracker.track({ | ||
| filterString: "[all[tiddlers+shadows]tag[$:/tags/BackgroundAction]!is[draft]]", | ||
| fnEnter: title => this.trackFilter(title), | ||
| fnLeave: (title, enterValue) => this.untrackFilter(enterValue), | ||
| fnChange: (title, enterValue) => { | ||
| this.untrackFilter(enterValue); | ||
| return this.trackFilter(title); | ||
| }, | ||
| fnProcess: changes => this.process(changes) | ||
| }); | ||
| } | ||
|
|
||
| trackFilter(title) { | ||
| const tiddler = this.wiki.getTiddler(title); | ||
| const id = this.nextTrackedFilterId++; | ||
| const tracker = new BackgroundActionTracker({ | ||
| wiki: this.wiki, | ||
| title, | ||
| trackFilter: tiddler.fields["track-filter"], | ||
| actions: tiddler.fields.text | ||
| }); | ||
| this.trackedFilters.set(id, tracker); | ||
| return id; | ||
| } | ||
|
|
||
| untrackFilter(enterValue) { | ||
| const tracker = this.trackedFilters.get(enterValue); | ||
| if(tracker) { | ||
| tracker.destroy(); | ||
| } | ||
| this.trackedFilters.delete(enterValue); | ||
| } | ||
|
|
||
| process(changes) { | ||
| for(const tracker of this.trackedFilters.values()) { | ||
| tracker.process(changes); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| Represents an individual tracked filter. Options include: | ||
| wiki: wiki to use | ||
| title: title of the tiddler being tracked | ||
| trackFilter: filter string to track changes | ||
| actions: actions to be executed when the filter changes | ||
| */ | ||
| class BackgroundActionTracker { | ||
| constructor({wiki, title, trackFilter, actions}) { | ||
| this.wiki = wiki; | ||
| this.title = title; | ||
| this.trackFilter = trackFilter; | ||
| this.actions = actions; | ||
| this.filterTracker = new $tw.FilterTracker(this.wiki); | ||
| this.hasChanged = false; | ||
| this.trackerID = this.filterTracker.track({ | ||
| filterString: this.trackFilter, | ||
| fnEnter: () => { this.hasChanged = true; }, | ||
| fnLeave: () => { this.hasChanged = true; }, | ||
| fnProcess: changes => { | ||
|
Check warning on line 78 in core/modules/background-actions.js
|
||
| if(this.hasChanged) { | ||
| this.hasChanged = false; | ||
| console.log("Processing background action", this.title); | ||
| const tiddler = this.wiki.getTiddler(this.title); | ||
| let doActions = true; | ||
| if(tiddler && tiddler.fields.platforms) { | ||
| doActions = false; | ||
| const platforms = $tw.utils.parseStringArray(tiddler.fields.platforms); | ||
| if(($tw.browser && platforms.includes("browser")) || ($tw.node && platforms.includes("node"))) { | ||
| doActions = true; | ||
| } | ||
| } | ||
| if(doActions) { | ||
| this.wiki.invokeActionString( | ||
| this.actions, | ||
| null, | ||
| { | ||
| currentTiddler: this.title | ||
| },{ | ||
| parentWidget: $tw.rootWidget | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| process(changes) { | ||
| this.filterTracker.handleChangeEvent(changes); | ||
| } | ||
|
|
||
| destroy() { | ||
| this.filterTracker.untrack(this.trackerID); | ||
| } | ||
| } | ||
|
|
||
| exports.BackgroundActionDispatcher = BackgroundActionDispatcher; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /*\ | ||
| title: $:/core/modules/filter-tracker.js | ||
| type: application/javascript | ||
| module-type: global | ||
|
|
||
| Class to track the results of a filter string | ||
|
|
||
| \*/ | ||
|
|
||
| "use strict"; | ||
|
|
||
| class FilterTracker { | ||
| constructor(wiki) { | ||
| this.wiki = wiki; | ||
| this.trackers = new Map(); | ||
| this.nextTrackerId = 1; | ||
| } | ||
|
|
||
| handleChangeEvent(changes) { | ||
| this.processTrackers(); | ||
| this.processChanges(changes); | ||
| } | ||
|
|
||
| /* | ||
| Add a tracker to the filter tracker. Returns null if any of the parameters are invalid, or a tracker id if the tracker was added successfully. Options include: | ||
| filterString: the filter string to track | ||
| fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue" | ||
| fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue) | ||
| fnChange: function to call when a tiddler changes in the filter results. Only called for filter results that identify a tiddler or shadow tiddler. Called as (title,enterValue), and may optionally return a replacement enterValue | ||
| fnProcess: function to call each time the tracker is processed, after any enter, leave or change functions are called. Called as (changes) | ||
| */ | ||
| track(options = {}) { | ||
| const { | ||
|
Check failure on line 33 in core/modules/filter-tracker.js
|
||
| filterString, | ||
| fnEnter, | ||
| fnLeave, | ||
| fnChange, | ||
| fnProcess | ||
| } = options; | ||
| const id = this.nextTrackerId++; | ||
| const tracker = { | ||
| id, | ||
| filterString, | ||
| fnEnter, | ||
| fnLeave, | ||
| fnChange, | ||
| fnProcess, | ||
| previousResults: [], | ||
| resultValues: {} | ||
| }; | ||
| this.trackers.set(id, tracker); | ||
| // Process the tracker | ||
| this.processTracker(id); | ||
| return id; | ||
| } | ||
|
|
||
| untrack(id) { | ||
| this.trackers.delete(id); | ||
| } | ||
|
|
||
| processTrackers() { | ||
| for(const id of this.trackers.keys()) { | ||
| this.processTracker(id); | ||
| } | ||
| } | ||
|
|
||
| processTracker(id) { | ||
| const tracker = this.trackers.get(id); | ||
| if(!tracker) return; | ||
| const results = []; | ||
| // Evaluate the filter and remove duplicate results | ||
| $tw.utils.each(this.wiki.filterTiddlers(tracker.filterString), title => { | ||
| $tw.utils.pushTop(results, title); | ||
| }); | ||
| // Process the newly entered results | ||
| results.forEach(title => { | ||
| if(!tracker.previousResults.includes(title) && !tracker.resultValues[title] && tracker.fnEnter) { | ||
| tracker.resultValues[title] = tracker.fnEnter(title) || true; | ||
| } | ||
| }); | ||
| // Process the results that have just left | ||
| tracker.previousResults.forEach(title => { | ||
| if(!results.includes(title) && tracker.resultValues[title] && tracker.fnLeave) { | ||
| tracker.fnLeave(title, tracker.resultValues[title]); | ||
| delete tracker.resultValues[title]; | ||
| } | ||
| }); | ||
| // Update the previous results | ||
| tracker.previousResults = results; | ||
| } | ||
|
|
||
| processChanges(changes) { | ||
| for(const tracker of this.trackers.values()) { | ||
| Object.keys(changes).forEach(title => { | ||
| if(title && tracker.previousResults.includes(title) && tracker.fnChange) { | ||
| tracker.resultValues[title] = tracker.fnChange(title, tracker.resultValues[title]) || tracker.resultValues[title]; | ||
| } | ||
| }); | ||
| if(tracker.fnProcess) { | ||
| tracker.fnProcess(changes); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| exports.FilterTracker = FilterTracker; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /*\ | ||
| title: $:/core/modules/info/mediaquerytracker.js | ||
| type: application/javascript | ||
| module-type: info | ||
|
|
||
| Initialise $:/info/ tiddlers derived from media queries via | ||
|
|
||
| \*/ | ||
|
|
||
| "use strict"; | ||
|
|
||
| exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) { | ||
| if($tw.browser) { | ||
| // Functions to start and stop tracking a particular media query tracker tiddler | ||
| function track(title) { | ||
| var result = {}, | ||
|
Check failure on line 16 in core/modules/info/mediaquerytracker.js
|
||
| tiddler = $tw.wiki.getTiddler(title); | ||
|
Check failure on line 17 in core/modules/info/mediaquerytracker.js
|
||
| if(tiddler) { | ||
|
Check failure on line 18 in core/modules/info/mediaquerytracker.js
|
||
| var mediaQueryRaw = tiddler.fields["media-query"], | ||
|
Check failure on line 19 in core/modules/info/mediaquerytracker.js
|
||
| infoTiddler = tiddler.fields["info-tiddler"], | ||
|
Check failure on line 20 in core/modules/info/mediaquerytracker.js
|
||
| infoTiddlerAlt = tiddler.fields["info-tiddler-alt"]; | ||
|
Check failure on line 21 in core/modules/info/mediaquerytracker.js
|
||
| var parser = $tw.wiki.parseText("text/vnd.tiddlywiki", mediaQueryRaw, {parseAsInline: true}); | ||
|
Check failure on line 22 in core/modules/info/mediaquerytracker.js
|
||
| var widgetNode = $tw.wiki.makeWidget(parser, {parentWidget: $tw.rootWidget}); | ||
|
Check failure on line 23 in core/modules/info/mediaquerytracker.js
|
||
| var container = $tw.fakeDocument.createElement("div"); | ||
| widgetNode.render(container, null); | ||
| var mediaQuery = container.textContent.trim(); | ||
| if(mediaQuery && infoTiddler) { | ||
| // Evaluate and track the media query | ||
| result.mqList = window.matchMedia(mediaQuery); | ||
| function getResultTiddlers() { | ||
| var value = result.mqList.matches ? "yes" : "no", | ||
| tiddlers = []; | ||
| tiddlers.push({title: infoTiddler, text: value}); | ||
| if(infoTiddlerAlt) { | ||
| tiddlers.push({title: infoTiddlerAlt, text: value}) | ||
| } | ||
| return tiddlers; | ||
| }; | ||
| updateInfoTiddlersCallback(getResultTiddlers()); | ||
| result.handler = function(event) { | ||
|
Check warning on line 40 in core/modules/info/mediaquerytracker.js
|
||
| updateInfoTiddlersCallback(getResultTiddlers()); | ||
| }; | ||
| result.mqList.addEventListener("change",result.handler); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function untrack(enterValue) { | ||
| if(enterValue.mqList && enterValue.handler) { | ||
| enterValue.mqList.removeEventListener("change",enterValue.handler); | ||
| } | ||
| } | ||
| // Track media query tracker tiddlers | ||
| function fnEnter(title) { | ||
| return track(title); | ||
| } | ||
| function fnLeave(title,enterValue) { | ||
| untrack(enterValue); | ||
| } | ||
| function fnChange(title,enterValue) { | ||
| untrack(enterValue); | ||
| return track(title); | ||
| } | ||
| $tw.filterTracker.track({ | ||
| filterString: "[all[tiddlers+shadows]tag[$:/tags/MediaQueryTracker]!is[draft]]", | ||
| fnEnter: fnEnter, | ||
| fnLeave: fnLeave, | ||
| fnChange: fnChange | ||
| }); | ||
| } | ||
| return []; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,13 +33,6 @@ exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) { | |
| // Screen size | ||
| infoTiddlerFields.push({title: "$:/info/browser/screen/width", text: window.screen.width.toString()}); | ||
| infoTiddlerFields.push({title: "$:/info/browser/screen/height", text: window.screen.height.toString()}); | ||
| // Dark mode through event listener on MediaQueryList | ||
| var mqList = window.matchMedia("(prefers-color-scheme: dark)"), | ||
| getDarkModeTiddler = function() {return {title: "$:/info/darkmode", text: mqList.matches ? "yes" : "no"};}; | ||
| infoTiddlerFields.push(getDarkModeTiddler()); | ||
| mqList.addListener(function(event) { | ||
| updateInfoTiddlersCallback([getDarkModeTiddler()]); | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed without a replacement? |
||
| // Language | ||
| infoTiddlerFields.push({title: "$:/info/browser/language", text: navigator.language || ""}); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.