bare-script 3.2.3 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ # Licensed under the MIT License
2
+ # https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
3
+
4
+
5
+ # Include sentinel
6
+ if systemGlobalGet('formsSentinel'):
7
+ return
8
+ endif
9
+ formsSentinel = true
10
+
11
+
12
+ # $function: formsTextElements
13
+ # $group: forms.bare
14
+ # $doc: Create a text input [element model](https://github.com/craigahobbs/element-model#readme)
15
+ # $arg id: The text input element ID
16
+ # $arg text: The initial text of the text input element
17
+ # $arg size: Optional (default is null). The size, in characters, of the text input element
18
+ # $arg onEnter: Optional (default is null). The text input element on-enter event handler
19
+ # $return: The text input [element model](https://github.com/craigahobbs/element-model#readme)
20
+ function formsTextElements(id, text, size, onEnter):
21
+ return objectNew( \
22
+ 'html', 'input', \
23
+ 'attr', objectNew( \
24
+ 'autocomplete', 'off', \
25
+ 'id', id, \
26
+ 'style', 'font-size: inherit; border: thin solid black; padding: 0.4em;', \
27
+ 'type', 'text', \
28
+ 'value', text, \
29
+ 'size', size \
30
+ ), \
31
+ 'callback', if(onEnter != null, objectNew('keyup', systemPartial(formsTextOnKeyup, onEnter))) \
32
+ )
33
+ endfunction
34
+
35
+
36
+ async function formsTextOnKeyup(onEnter, keyCode):
37
+ if keyCode == 13:
38
+ onEnter()
39
+ endif
40
+ endfunction
41
+
42
+
43
+ # $function: formsLinkButtonElements
44
+ # $group: forms.bare
45
+ # $doc: Create a link button [element model](https://github.com/craigahobbs/element-model#readme)
46
+ # $arg text: The link button's text
47
+ # $arg onClick: The link button's click event handler
48
+ # $return: The link button [element model](https://github.com/craigahobbs/element-model#readme)
49
+ function formsLinkButtonElements(text, onClick):
50
+ return objectNew( \
51
+ 'html', 'a', \
52
+ 'attr', objectNew('style', 'cursor: pointer; user-select: none;'), \
53
+ 'elem', objectNew('text', text), \
54
+ 'callback', objectNew('click', onClick) \
55
+ )
56
+ endfunction
57
+
58
+
59
+ # $function: formsLinkElements
60
+ # $group: forms.bare
61
+ # $doc: Create a link [element model](https://github.com/craigahobbs/element-model#readme)
62
+ # $arg text: The link's text
63
+ # $arg url: The link's URL. If null, the link is rendered as text.
64
+ # $return: The link [element model](https://github.com/craigahobbs/element-model#readme)
65
+ function formsLinkElements(text, url):
66
+ if url == null:
67
+ return objectNew( \
68
+ 'html', 'span', \
69
+ 'attr', objectNew('style', 'user-select: none;'), \
70
+ 'elem', objectNew('text', text) \
71
+ )
72
+ endif
73
+
74
+ return objectNew( \
75
+ 'html', 'a', \
76
+ 'attr', objectNew('href', documentURL(url)), \
77
+ 'elem', objectNew('text', text) \
78
+ )
79
+ endfunction
@@ -6,74 +6,7 @@
6
6
  if systemGlobalGet('formsSentinel'):
7
7
  return
8
8
  endif
9
- formsSentinel = true
10
9
 
11
10
 
12
- # $function: formsTextElements
13
- # $group: forms.mds
14
- # $doc: Create a text input [element model](https://github.com/craigahobbs/element-model#readme)
15
- # $arg id: The text input element ID
16
- # $arg text: The initial text of the text input element
17
- # $arg size: Optional (default is null). The size, in characters, of the text input element
18
- # $arg onEnter: Optional (default is null). The text input element on-enter event handler
19
- # $return: The text input [element model](https://github.com/craigahobbs/element-model#readme)
20
- function formsTextElements(id, text, size, onEnter):
21
- return objectNew( \
22
- 'html', 'input', \
23
- 'attr', objectNew( \
24
- 'autocomplete', 'off', \
25
- 'id', id, \
26
- 'style', 'font-size: inherit; border: thin solid black; padding: 0.4em;', \
27
- 'type', 'text', \
28
- 'value', text, \
29
- 'size', size \
30
- ), \
31
- 'callback', if(onEnter != null, objectNew('keyup', systemPartial(formsTextOnKeyup, onEnter))) \
32
- )
33
- endfunction
34
-
35
-
36
- async function formsTextOnKeyup(onEnter, keyCode):
37
- if keyCode == 13:
38
- onEnter()
39
- endif
40
- endfunction
41
-
42
-
43
- # $function: formsLinkButtonElements
44
- # $group: forms.mds
45
- # $doc: Create a link button [element model](https://github.com/craigahobbs/element-model#readme)
46
- # $arg text: The link button's text
47
- # $arg onClick: The link button's click event handler
48
- # $return: The link button [element model](https://github.com/craigahobbs/element-model#readme)
49
- function formsLinkButtonElements(text, onClick):
50
- return objectNew( \
51
- 'html', 'a', \
52
- 'attr', objectNew('style', 'cursor: pointer; user-select: none;'), \
53
- 'elem', objectNew('text', text), \
54
- 'callback', objectNew('click', onClick) \
55
- )
56
- endfunction
57
-
58
-
59
- # $function: formsLinkElements
60
- # $group: forms.mds
61
- # $doc: Create a link [element model](https://github.com/craigahobbs/element-model#readme)
62
- # $arg text: The link's text
63
- # $arg url: The link's URL. If null, the link is rendered as text.
64
- # $return: The link [element model](https://github.com/craigahobbs/element-model#readme)
65
- function formsLinkElements(text, url):
66
- if url == null:
67
- return objectNew( \
68
- 'html', 'span', \
69
- 'attr', objectNew('style', 'user-select: none;'), \
70
- 'elem', objectNew('text', text) \
71
- )
72
- endif
73
-
74
- return objectNew( \
75
- 'html', 'a', \
76
- 'attr', objectNew('href', documentURL(url)), \
77
- 'elem', objectNew('text', text) \
78
- )
79
- endfunction
11
+ systemLog('MarkdownUp - forms.mds: forms.mds is now forms.bare - please update before 2025-06-01')
12
+ include 'forms.bare'
@@ -0,0 +1,236 @@
1
+ # Licensed under the MIT License
2
+ # https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
3
+
4
+
5
+ # Include sentinel
6
+ if systemGlobalGet('pagerSentinel'):
7
+ return
8
+ endif
9
+ pagerSentinel = true
10
+
11
+
12
+ include 'args.bare'
13
+
14
+
15
+ # The pager model
16
+ pagerTypes = schemaParse( \
17
+ 'group "pager.bare"', \
18
+ '', \
19
+ '', \
20
+ '# A pager application model', \
21
+ 'struct Pager', \
22
+ '', \
23
+ " # The application's pages", \
24
+ ' PagerPage[len > 0] pages', \
25
+ '', \
26
+ '', \
27
+ '# A page model', \
28
+ 'struct PagerPage', \
29
+ '', \
30
+ ' # The page name', \
31
+ ' string name', \
32
+ '', \
33
+ ' # If true, the page is hidden', \
34
+ ' optional bool hidden', \
35
+ '', \
36
+ ' # The page type', \
37
+ ' PagerPageType type', \
38
+ '', \
39
+ '', \
40
+ '# The page type', \
41
+ 'union PagerPageType', \
42
+ '', \
43
+ ' # A function page', \
44
+ ' PagerPageFunction function', \
45
+ '', \
46
+ ' # A markdown resource page', \
47
+ ' PagerPageMarkdown markdown', \
48
+ '', \
49
+ ' # A navigation link', \
50
+ ' PagerPageLink link', \
51
+ '', \
52
+ '', \
53
+ '# A page function', \
54
+ 'struct PagerPageFunction', \
55
+ '', \
56
+ ' # The page function', \
57
+ ' object function', \
58
+ '', \
59
+ ' # The page title', \
60
+ ' optional string title', \
61
+ '', \
62
+ '', \
63
+ '# A Markdown resource page', \
64
+ 'struct PagerPageMarkdown', \
65
+ '', \
66
+ ' # The Markdown resource URL', \
67
+ ' string url', \
68
+ '', \
69
+ '', \
70
+ '# A page link', \
71
+ 'struct PagerPageLink', \
72
+ '', \
73
+ ' # The link URL', \
74
+ ' string url' \
75
+ )
76
+
77
+
78
+ # $function: pagerValidate
79
+ # $group: pager.bare
80
+ # $doc: Validate a pager model
81
+ # $arg pagerModel: The [pager model](includeModel.html#var.vName='Pager')
82
+ # $return: The validated [pager model](includeModel.html#var.vName='Pager') or null if validation fails
83
+ function pagerValidate(pagerModel):
84
+ return schemaValidate(pagerTypes, 'Pager', pagerModel)
85
+ endfunction
86
+
87
+
88
+ # $function: pagerMain
89
+ # $group: pager.bare
90
+ # $doc: The pager application main entry point
91
+ # $arg pagerModel: The [pager model](includeModel.html#var.vName='Pager')
92
+ # $arg options: The pager application options. The following options are available:
93
+ # $arg options: - **arguments** - The [arguments model](includeModel.html#var.vName='ArgsArguments').
94
+ # $arg options: Must contain a string argument named "page".
95
+ # $arg options: - **hideMenu** - Hide the menu links
96
+ # $arg options: - **hideNav** - Hide the navigation links
97
+ # $arg options: - **start** - The start page name
98
+ async function pagerMain(pagerModel, options):
99
+ if options == null:
100
+ options = objectNew()
101
+ endif
102
+
103
+ # Validate the pager model
104
+ pagerModel = pagerValidate(pagerModel)
105
+ if pagerModel == null:
106
+ return
107
+ endif
108
+
109
+ # Compute the visible and navigable pages
110
+ pages = objectGet(pagerModel, 'pages')
111
+ visiblePages = arrayNew()
112
+ navPages = arrayNew()
113
+ for page in pages:
114
+ # Visible page?
115
+ if !objectGet(page, 'hidden'):
116
+ arrayPush(visiblePages, page)
117
+
118
+ # Navigable page?
119
+ pageTypeKey = arrayGet(objectKeys(objectGet(page, 'type')), 0)
120
+ if pageTypeKey != 'link':
121
+ arrayPush(navPages, page)
122
+ endif
123
+ endif
124
+ endfor
125
+
126
+ # Parse arguments
127
+ startPageName = objectGet(options, 'start', if(arrayLength(navPages), objectGet(arrayGet(navPages, 0), 'name'), null))
128
+ if objectHas(options, 'arguments'):
129
+ arguments = argsValidate(objectGet(options, 'arguments'))
130
+ if arguments == null:
131
+ return
132
+ endif
133
+ else:
134
+ arguments = arrayNew(objectNew('name', 'page', 'default', startPageName))
135
+ endif
136
+ args = argsParse(arguments)
137
+
138
+ # Determine the current page
139
+ curPage = null
140
+ startPage = null
141
+ for page in pages:
142
+ if objectGet(page, 'name') == objectGet(args, 'page'):
143
+ curPage = page
144
+ endif
145
+ if objectGet(page, 'name') == startPageName:
146
+ startPage = page
147
+ endif
148
+ endfor
149
+ if startPage == null:
150
+ systemLogDebug('MarkdownUp - pager.bare: Unknown start page' + if(startPageName != null, '"' + startPageName + '"', ''))
151
+ return
152
+ endif
153
+ if curPage == null:
154
+ curPage = startPage
155
+ endif
156
+
157
+ # Determine the current page's navigable index, if any
158
+ ixCurPage = -1
159
+ for navPage, ixNavPage in navPages:
160
+ if objectGet(navPage, 'name') == objectGet(curPage, 'name'):
161
+ ixCurPage = ixNavPage
162
+ break
163
+ endif
164
+ endfor
165
+
166
+ # Render the menu
167
+ if !objectGet(options, 'hideMenu'):
168
+ for page, ixPage in visiblePages:
169
+ pageName = objectGet(page, 'name')
170
+ pageType = objectGet(page, 'type')
171
+ pageTypeKey = arrayGet(objectKeys(pageType), 0)
172
+
173
+ # Render the menu link
174
+ pageNameNbsp = stringReplace(pageName, ' ', ' ')
175
+ separator = if(ixPage != arrayLength(visiblePages) - 1, ' |', '')
176
+ if pageTypeKey == 'link':
177
+ pageLinkURL = objectGet(objectGet(pageType, 'link'), 'url')
178
+ markdownPrint('[' + markdownEscape(pageNameNbsp) + '](' + urlEncode(pageLinkURL) + ')' + separator)
179
+ elif pageName == objectGet(curPage, 'name'):
180
+ markdownPrint(markdownEscape(pageNameNbsp) + separator)
181
+ else:
182
+ markdownPrint(argsLink(arguments, pageNameNbsp, objectNew('page', pageName)) + separator)
183
+ endif
184
+ endfor
185
+ markdownPrint('')
186
+ endif
187
+
188
+ # Render the start/next/prev buttons
189
+ if !objectGet(options, 'hideNav') && arrayLength(navPages) > 1 && ixCurPage != -1:
190
+ if startPageName == objectGet(curPage, 'name'):
191
+ startPageName = null
192
+ endif
193
+ prevPageName = if(ixCurPage != -1 && ixCurPage - 1 >= 0, objectGet(arrayGet(navPages, ixCurPage - 1), 'name'), null)
194
+ nextPageName = if(ixCurPage != -1 && ixCurPage + 1 < arrayLength(navPages), objectGet(arrayGet(navPages, ixCurPage + 1), 'name'), null)
195
+ markdownPrint( \
196
+ '(&nbsp;' + if(startPageName != null, argsLink(arguments, 'Start', objectNew('page', startPageName)), 'Start') + '&nbsp;|', \
197
+ if(prevPageName != null, argsLink(arguments, 'Previous', objectNew('page', prevPageName)), 'Previous') + '&nbsp;|', \
198
+ if(nextPageName != null, argsLink(arguments, 'Next', objectNew('page', nextPageName)), 'Next') + '&nbsp;)', \
199
+ '' \
200
+ )
201
+ endif
202
+
203
+ # Function page?
204
+ curPageType = objectGet(curPage, 'type')
205
+ curPageTypeKey = arrayGet(objectKeys(curPageType), 0)
206
+ if curPageTypeKey == 'function':
207
+ # Set the title
208
+ title = objectGet(objectGet(curPageType, 'function'), 'title')
209
+ if title != null:
210
+ documentSetTitle(title)
211
+ markdownPrint('# ' + markdownEscape(title), '')
212
+ endif
213
+
214
+ # Call the page function
215
+ pageFn = objectGet(objectGet(curPageType, 'function'), 'function')
216
+ pageFn(args)
217
+ elif curPageTypeKey == 'markdown':
218
+ # Fetch the Markdown text
219
+ url = objectGet(objectGet(curPageType, 'markdown'), 'url')
220
+ markdownText = systemFetch(url)
221
+ if markdownText == null:
222
+ markdownPrint('**Error:** Failed to load "' + url + '"')
223
+ else:
224
+ # Compute and set the page title
225
+ markdownModel = markdownParse(markdownText)
226
+ title = markdownTitle(markdownModel)
227
+ if title == null:
228
+ title = 'No Title'
229
+ endif
230
+ documentSetTitle(title)
231
+
232
+ # Render the Markdown text
233
+ markdownPrint('', markdownText)
234
+ endif
235
+ endif
236
+ endfunction
@@ -1,235 +1,12 @@
1
1
  # Licensed under the MIT License
2
2
  # https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
3
3
 
4
- include <args.mds>
5
-
6
4
 
7
5
  # Include sentinel
8
6
  if systemGlobalGet('pagerSentinel'):
9
7
  return
10
8
  endif
11
- pagerSentinel = true
12
-
13
-
14
- # The pager model
15
- pagerTypes = schemaParse( \
16
- 'group "pager.mds"', \
17
- '', \
18
- '', \
19
- '# A pager application model', \
20
- 'struct Pager', \
21
- '', \
22
- " # The application's pages", \
23
- ' PagerPage[len > 0] pages', \
24
- '', \
25
- '', \
26
- '# A page model', \
27
- 'struct PagerPage', \
28
- '', \
29
- ' # The page name', \
30
- ' string name', \
31
- '', \
32
- ' # If true, the page is hidden', \
33
- ' optional bool hidden', \
34
- '', \
35
- ' # The page type', \
36
- ' PagerPageType type', \
37
- '', \
38
- '', \
39
- '# The page type', \
40
- 'union PagerPageType', \
41
- '', \
42
- ' # A function page', \
43
- ' PagerPageFunction function', \
44
- '', \
45
- ' # A markdown resource page', \
46
- ' PagerPageMarkdown markdown', \
47
- '', \
48
- ' # A navigation link', \
49
- ' PagerPageLink link', \
50
- '', \
51
- '', \
52
- '# A page function', \
53
- 'struct PagerPageFunction', \
54
- '', \
55
- ' # The page function', \
56
- ' object function', \
57
- '', \
58
- ' # The page title', \
59
- ' optional string title', \
60
- '', \
61
- '', \
62
- '# A Markdown resource page', \
63
- 'struct PagerPageMarkdown', \
64
- '', \
65
- ' # The Markdown resource URL', \
66
- ' string url', \
67
- '', \
68
- '', \
69
- '# A page link', \
70
- 'struct PagerPageLink', \
71
- '', \
72
- ' # The link URL', \
73
- ' string url' \
74
- )
75
-
76
-
77
- # $function: pagerValidate
78
- # $group: pager.mds
79
- # $doc: Validate a pager model
80
- # $arg pagerModel: The [pager model](includeModel.html#var.vName='Pager')
81
- # $return: The validated [pager model](includeModel.html#var.vName='Pager') or null if validation fails
82
- function pagerValidate(pagerModel):
83
- return schemaValidate(pagerTypes, 'Pager', pagerModel)
84
- endfunction
85
-
86
-
87
- # $function: pagerMain
88
- # $group: pager.mds
89
- # $doc: The pager application main entry point
90
- # $arg pagerModel: The [pager model](includeModel.html#var.vName='Pager')
91
- # $arg options: The pager application options. The following options are available:
92
- # $arg options: - **arguments** - The [arguments model](includeModel.html#var.vName='ArgsArguments').
93
- # $arg options: Must contain a string argument named "page".
94
- # $arg options: - **hideMenu** - Hide the menu links
95
- # $arg options: - **hideNav** - Hide the navigation links
96
- # $arg options: - **start** - The start page name
97
- async function pagerMain(pagerModel, options):
98
- if options == null:
99
- options = objectNew()
100
- endif
101
-
102
- # Validate the pager model
103
- pagerModel = pagerValidate(pagerModel)
104
- if pagerModel == null:
105
- return
106
- endif
107
-
108
- # Compute the visible and navigable pages
109
- pages = objectGet(pagerModel, 'pages')
110
- visiblePages = arrayNew()
111
- navPages = arrayNew()
112
- for page in pages:
113
- # Visible page?
114
- if !objectGet(page, 'hidden'):
115
- arrayPush(visiblePages, page)
116
-
117
- # Navigable page?
118
- pageTypeKey = arrayGet(objectKeys(objectGet(page, 'type')), 0)
119
- if pageTypeKey != 'link':
120
- arrayPush(navPages, page)
121
- endif
122
- endif
123
- endfor
124
-
125
- # Parse arguments
126
- startPageName = objectGet(options, 'start', if(arrayLength(navPages), objectGet(arrayGet(navPages, 0), 'name'), null))
127
- if objectHas(options, 'arguments'):
128
- arguments = argsValidate(objectGet(options, 'arguments'))
129
- if arguments == null:
130
- return
131
- endif
132
- else:
133
- arguments = arrayNew(objectNew('name', 'page', 'default', startPageName))
134
- endif
135
- args = argsParse(arguments)
136
-
137
- # Determine the current page
138
- curPage = null
139
- startPage = null
140
- for page in pages:
141
- if objectGet(page, 'name') == objectGet(args, 'page'):
142
- curPage = page
143
- endif
144
- if objectGet(page, 'name') == startPageName:
145
- startPage = page
146
- endif
147
- endfor
148
- if startPage == null:
149
- systemLogDebug('MarkdownUp - pager.mds: Unknown start page' + if(startPageName != null, '"' + startPageName + '"', ''))
150
- return
151
- endif
152
- if curPage == null:
153
- curPage = startPage
154
- endif
155
-
156
- # Determine the current page's navigable index, if any
157
- ixCurPage = -1
158
- for navPage, ixNavPage in navPages:
159
- if objectGet(navPage, 'name') == objectGet(curPage, 'name'):
160
- ixCurPage = ixNavPage
161
- break
162
- endif
163
- endfor
164
-
165
- # Render the menu
166
- if !objectGet(options, 'hideMenu'):
167
- for page, ixPage in visiblePages:
168
- pageName = objectGet(page, 'name')
169
- pageType = objectGet(page, 'type')
170
- pageTypeKey = arrayGet(objectKeys(pageType), 0)
171
-
172
- # Render the menu link
173
- pageNameNbsp = stringReplace(pageName, ' ', '&nbsp;')
174
- separator = if(ixPage != arrayLength(visiblePages) - 1, '&nbsp;|', '')
175
- if pageTypeKey == 'link':
176
- pageLinkURL = objectGet(objectGet(pageType, 'link'), 'url')
177
- markdownPrint('[' + markdownEscape(pageNameNbsp) + '](' + urlEncode(pageLinkURL) + ')' + separator)
178
- elif pageName == objectGet(curPage, 'name'):
179
- markdownPrint(markdownEscape(pageNameNbsp) + separator)
180
- else:
181
- markdownPrint(argsLink(arguments, pageNameNbsp, objectNew('page', pageName)) + separator)
182
- endif
183
- endfor
184
- markdownPrint('')
185
- endif
186
-
187
- # Render the start/next/prev buttons
188
- if !objectGet(options, 'hideNav') && arrayLength(navPages) > 1 && ixCurPage != -1:
189
- if startPageName == objectGet(curPage, 'name'):
190
- startPageName = null
191
- endif
192
- prevPageName = if(ixCurPage != -1 && ixCurPage - 1 >= 0, objectGet(arrayGet(navPages, ixCurPage - 1), 'name'), null)
193
- nextPageName = if(ixCurPage != -1 && ixCurPage + 1 < arrayLength(navPages), objectGet(arrayGet(navPages, ixCurPage + 1), 'name'), null)
194
- markdownPrint( \
195
- '(&nbsp;' + if(startPageName != null, argsLink(arguments, 'Start', objectNew('page', startPageName)), 'Start') + '&nbsp;|', \
196
- if(prevPageName != null, argsLink(arguments, 'Previous', objectNew('page', prevPageName)), 'Previous') + '&nbsp;|', \
197
- if(nextPageName != null, argsLink(arguments, 'Next', objectNew('page', nextPageName)), 'Next') + '&nbsp;)', \
198
- '' \
199
- )
200
- endif
201
-
202
- # Function page?
203
- curPageType = objectGet(curPage, 'type')
204
- curPageTypeKey = arrayGet(objectKeys(curPageType), 0)
205
- if curPageTypeKey == 'function':
206
- # Set the title
207
- title = objectGet(objectGet(curPageType, 'function'), 'title')
208
- if title != null:
209
- documentSetTitle(title)
210
- markdownPrint('# ' + markdownEscape(title), '')
211
- endif
212
9
 
213
- # Call the page function
214
- pageFn = objectGet(objectGet(curPageType, 'function'), 'function')
215
- pageFn(args)
216
- elif curPageTypeKey == 'markdown':
217
- # Fetch the Markdown text
218
- url = objectGet(objectGet(curPageType, 'markdown'), 'url')
219
- markdownText = systemFetch(url)
220
- if markdownText == null:
221
- markdownPrint('**Error:** Failed to load "' + url + '"')
222
- else:
223
- # Compute and set the page title
224
- markdownModel = markdownParse(markdownText)
225
- title = markdownTitle(markdownModel)
226
- if title == null:
227
- title = 'No Title'
228
- endif
229
- documentSetTitle(title)
230
10
 
231
- # Render the Markdown text
232
- markdownPrint('', markdownText)
233
- endif
234
- endif
235
- endfunction
11
+ systemLog('MarkdownUp - pager.mds: pager.mds is now pager.bare - please update before 2025-06-01')
12
+ include 'pager.bare'