datafolder 1.0.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.
Files changed (182) hide show
  1. package/README.md +169 -0
  2. package/index.js +3 -0
  3. package/package.json +27 -0
  4. package/sample.js +37 -0
  5. package/scripts/airbnb.js +73 -0
  6. package/scripts/airbnb2.js +74 -0
  7. package/scripts/airbnb2_queries.js +231 -0
  8. package/scripts/airbnb_queries.js +264 -0
  9. package/scripts/downloadFile.js +42 -0
  10. package/scripts/express.js +46 -0
  11. package/scripts/fastify.js +79 -0
  12. package/scripts/flights.js +75 -0
  13. package/scripts/flights2.js +81 -0
  14. package/scripts/flights2_queries.js +453 -0
  15. package/scripts/flights_queries.js +403 -0
  16. package/src/QyAcl.js +252 -0
  17. package/src/QyAclSaver.js +14 -0
  18. package/src/QyAclSaver_Worker.js +29 -0
  19. package/src/QyAclWriter.js +19 -0
  20. package/src/QyBatch.js +501 -0
  21. package/src/QyBinWriter.js +140 -0
  22. package/src/QyCD.js +61 -0
  23. package/src/QyCache.js +212 -0
  24. package/src/QyCompressor.js +60 -0
  25. package/src/QyCompressor_Worker.js +13 -0
  26. package/src/QyDB.js +122 -0
  27. package/src/QyDefaultOptions.js +59 -0
  28. package/src/QyDir.js +192 -0
  29. package/src/QyFetch.js +38 -0
  30. package/src/QyFile.js +124 -0
  31. package/src/QyFileContentUtils.js +175 -0
  32. package/src/QyFileLogger.js +58 -0
  33. package/src/QyIndex.js +237 -0
  34. package/src/QyIndexPropTree.js +92 -0
  35. package/src/QyIntersectNode.js +48 -0
  36. package/src/QyItem.js +105 -0
  37. package/src/QyJsonSaver.js +20 -0
  38. package/src/QyKVData.js +289 -0
  39. package/src/QyKVDataCleaner.js +17 -0
  40. package/src/QyKVDataCleaner_Worker.js +94 -0
  41. package/src/QyKVDataLoader.js +65 -0
  42. package/src/QyKVDataSaver.js +17 -0
  43. package/src/QyKVDataSaver_Worker.js +81 -0
  44. package/src/QyLogFileSaver.js +14 -0
  45. package/src/QyLogFileSaver_Worker.js +26 -0
  46. package/src/QyLogger.js +76 -0
  47. package/src/QyMessageWorker.js +41 -0
  48. package/src/QyMessager.js +84 -0
  49. package/src/QyMessager_Run.js +13 -0
  50. package/src/QyMod.js +15 -0
  51. package/src/QyOpRunner.js +73 -0
  52. package/src/QyQueue.js +60 -0
  53. package/src/QySaver.js +83 -0
  54. package/src/QySnapshotCompactor.js +17 -0
  55. package/src/QySnapshotCompactor_Worker.js +151 -0
  56. package/src/QySnapshotSaver.js +17 -0
  57. package/src/QySnapshotSaver_Worker.js +164 -0
  58. package/src/QySnapshots.js +354 -0
  59. package/src/QyStructure.js +50 -0
  60. package/src/QyTrigger.js +133 -0
  61. package/src/QyUnionNode.js +105 -0
  62. package/src/QyUtils.js +250 -0
  63. package/src/QyWorker.js +33 -0
  64. package/src/hackernews.js +93 -0
  65. package/src/rpc/evalCode.js +9 -0
  66. package/src/rpc/getFileContent.js +16 -0
  67. package/src/rpc/getSubItems.js +32 -0
  68. package/src/rpc/queryFiles.js +33 -0
  69. package/src/rpc/reloadRpc.js +1 -0
  70. package/src/simulate.js +114 -0
  71. package/src/simulate2.js +110 -0
  72. package/src/soc_pokec.js +43 -0
  73. package/static/bootstrap-5.3.8-dist/css/bootstrap.min.css +6 -0
  74. package/static/bootstrap-5.3.8-dist/js/bootstrap.bundle.js +6312 -0
  75. package/static/datafolderui/QyStyledElement.js +30 -0
  76. package/static/datafolderui/QyUIFolderTree.js +203 -0
  77. package/static/datafolderui/QyUIUtils.js +42 -0
  78. package/static/datafolderui/display-tree.js +108 -0
  79. package/static/datafolderui/explore-tree.js +122 -0
  80. package/static/datafolderui/folder-tree.js +5 -0
  81. package/static/datafolderui/hscrpt.js +25 -0
  82. package/static/datafolderui/index.css +6 -0
  83. package/static/datafolderui/index.html +20 -0
  84. package/static/datafolderui/json-view.js +74 -0
  85. package/static/datafolderui/kv-input.js +66 -0
  86. package/static/datafolderui/list-input.js +52 -0
  87. package/static/datafolderui/main-page.js +98 -0
  88. package/static/datafolderui/num-input.js +27 -0
  89. package/static/datafolderui/query-editor.js +229 -0
  90. package/static/datafolderui/querySelectorShadowRoot.js +24 -0
  91. package/static/datafolderui/resizable-input.js +67 -0
  92. package/static/favicon.ico +0 -0
  93. package/static/icons-1.13.1/font/bootstrap-icons.min.css +5 -0
  94. package/static/icons-1.13.1/font/fonts/bootstrap-icons.woff +0 -0
  95. package/static/icons-1.13.1/font/fonts/bootstrap-icons.woff2 +0 -0
  96. package/static/json-view/dist/jsonview.js +433 -0
  97. package/static/tree.js/tree.css +106 -0
  98. package/static/tree.js/tree.js +374 -0
  99. package/static/w2ui/dist/w2ui.min.css +2 -0
  100. package/static/w2ui/src/less/icons/icons.json +1 -0
  101. package/static/w2ui/src/less/icons/preview.html +33 -0
  102. package/static/w2ui/src/less/icons/readme.md +15 -0
  103. package/static/w2ui/src/less/icons/svg/box.svg +3 -0
  104. package/static/w2ui/src/less/icons/svg/check.svg +3 -0
  105. package/static/w2ui/src/less/icons/svg/colors.svg +3 -0
  106. package/static/w2ui/src/less/icons/svg/columns.svg +5 -0
  107. package/static/w2ui/src/less/icons/svg/cross.svg +4 -0
  108. package/static/w2ui/src/less/icons/svg/drop.svg +6 -0
  109. package/static/w2ui/src/less/icons/svg/empty.svg +3 -0
  110. package/static/w2ui/src/less/icons/svg/eye-dropper.svg +4 -0
  111. package/static/w2ui/src/less/icons/svg/info.svg +8 -0
  112. package/static/w2ui/src/less/icons/svg/paste.svg +4 -0
  113. package/static/w2ui/src/less/icons/svg/pencil.svg +5 -0
  114. package/static/w2ui/src/less/icons/svg/plus.svg +3 -0
  115. package/static/w2ui/src/less/icons/svg/reload.svg +5 -0
  116. package/static/w2ui/src/less/icons/svg/search.svg +3 -0
  117. package/static/w2ui/src/less/icons/svg/settings.svg +8 -0
  118. package/static/w2ui/src/less/icons/w2ui-font.css +36 -0
  119. package/static/w2ui/src/less/icons/w2ui-font.woff +0 -0
  120. package/static/w2ui/src/less/src/buttons.less +184 -0
  121. package/static/w2ui/src/less/src/common.less +541 -0
  122. package/static/w2ui/src/less/src/fields.less +302 -0
  123. package/static/w2ui/src/less/src/form.less +319 -0
  124. package/static/w2ui/src/less/src/grid.less +1057 -0
  125. package/static/w2ui/src/less/src/icons.less +37 -0
  126. package/static/w2ui/src/less/src/layout.less +86 -0
  127. package/static/w2ui/src/less/src/mixins.less +87 -0
  128. package/static/w2ui/src/less/src/popup.less +277 -0
  129. package/static/w2ui/src/less/src/sidebar.less +343 -0
  130. package/static/w2ui/src/less/src/tabs.less +145 -0
  131. package/static/w2ui/src/less/src/toolbar.less +219 -0
  132. package/static/w2ui/src/less/src/tooltip.less +948 -0
  133. package/static/w2ui/src/less/w2ui.less +196 -0
  134. package/static/w2ui/src/locale/az-az.json +114 -0
  135. package/static/w2ui/src/locale/ba-ba.json +114 -0
  136. package/static/w2ui/src/locale/bg-bg.json +114 -0
  137. package/static/w2ui/src/locale/ca-es.json +114 -0
  138. package/static/w2ui/src/locale/da-dk.json +114 -0
  139. package/static/w2ui/src/locale/de-de.json +114 -0
  140. package/static/w2ui/src/locale/en-gb.json +17 -0
  141. package/static/w2ui/src/locale/en-us.json +17 -0
  142. package/static/w2ui/src/locale/es-ar.json +115 -0
  143. package/static/w2ui/src/locale/es-cr.json +119 -0
  144. package/static/w2ui/src/locale/es-es.json +114 -0
  145. package/static/w2ui/src/locale/es-mx.json +114 -0
  146. package/static/w2ui/src/locale/fr-fr.json +114 -0
  147. package/static/w2ui/src/locale/gl-es.json +114 -0
  148. package/static/w2ui/src/locale/hr-hr.json +114 -0
  149. package/static/w2ui/src/locale/hu-hu.json +114 -0
  150. package/static/w2ui/src/locale/id-id.json +114 -0
  151. package/static/w2ui/src/locale/it-it.json +114 -0
  152. package/static/w2ui/src/locale/ja-jp.json +114 -0
  153. package/static/w2ui/src/locale/kk-kz.json +116 -0
  154. package/static/w2ui/src/locale/ko-kr.json +114 -0
  155. package/static/w2ui/src/locale/lt-lt.json +114 -0
  156. package/static/w2ui/src/locale/nl-nl.json +114 -0
  157. package/static/w2ui/src/locale/no-no.json +114 -0
  158. package/static/w2ui/src/locale/pl-pl.json +114 -0
  159. package/static/w2ui/src/locale/pt-br.json +114 -0
  160. package/static/w2ui/src/locale/ru-ru.json +116 -0
  161. package/static/w2ui/src/locale/sk-sk.json +114 -0
  162. package/static/w2ui/src/locale/sl-si.json +116 -0
  163. package/static/w2ui/src/locale/sr-rs.json +114 -0
  164. package/static/w2ui/src/locale/tr-tr.json +114 -0
  165. package/static/w2ui/src/locale/uk-ua.json +114 -0
  166. package/static/w2ui/src/locale/zh-cn.json +114 -0
  167. package/static/w2ui/src/locale/zh-tw.json +114 -0
  168. package/static/w2ui/src/query.js +583 -0
  169. package/static/w2ui/src/readme.md +11 -0
  170. package/static/w2ui/src/w2base.js +311 -0
  171. package/static/w2ui/src/w2compat.js +207 -0
  172. package/static/w2ui/src/w2field.js +1854 -0
  173. package/static/w2ui/src/w2form.js +2411 -0
  174. package/static/w2ui/src/w2grid.js +8916 -0
  175. package/static/w2ui/src/w2layout.js +1194 -0
  176. package/static/w2ui/src/w2locale.js +129 -0
  177. package/static/w2ui/src/w2popup.js +909 -0
  178. package/static/w2ui/src/w2sidebar.js +1769 -0
  179. package/static/w2ui/src/w2tabs.js +669 -0
  180. package/static/w2ui/src/w2toolbar.js +1180 -0
  181. package/static/w2ui/src/w2tooltip.js +3134 -0
  182. package/static/w2ui/src/w2utils.js +2457 -0
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Part of w2ui 2.0 library
3
+ * - Dependencies: w2utils
4
+ * - on/off/trigger methods id not showing in help
5
+ * - refactored with event object
6
+ *
7
+ * Chanes in 2.0.+
8
+ * - added unmount that cleans up the box
9
+ *
10
+ */
11
+
12
+ import { w2ui, w2utils, query } from './w2utils.js'
13
+
14
+ class w2event {
15
+ constructor(owner, edata) {
16
+ Object.assign(this, {
17
+ type: edata.type ?? null,
18
+ detail: edata,
19
+ owner,
20
+ target: edata.target ?? null,
21
+ phase: edata.phase ?? 'before',
22
+ object: edata.object ?? null,
23
+ execute: null,
24
+ isStopped: false,
25
+ isCancelled: false,
26
+ onComplete: null,
27
+ listeners: []
28
+ })
29
+ delete edata.type
30
+ delete edata.target
31
+ delete edata.object
32
+ this.complete = new Promise((resolve, reject) => {
33
+ this._resolve = resolve
34
+ this._reject = reject
35
+ })
36
+ // needed empty catch function so that promise will not show error in the console
37
+ this.complete.catch(() => {})
38
+ }
39
+
40
+ finish(detail) {
41
+ if (detail) {
42
+ w2utils.extend(this.detail, detail)
43
+ }
44
+ this.phase = 'after'
45
+ this.owner.trigger.call(this.owner, this)
46
+ }
47
+
48
+ done(func) {
49
+ this.listeners.push(func)
50
+ }
51
+
52
+ preventDefault() {
53
+ this._reject()
54
+ this.isCancelled = true
55
+ }
56
+
57
+ stopPropagation() {
58
+ this.isStopped = true
59
+ }
60
+ }
61
+
62
+ class w2base {
63
+ /**
64
+ * Initializes base object for w2ui, registers it with w2ui object
65
+ *
66
+ * @param {string} name - name of the object
67
+ * @returns
68
+ */
69
+ constructor(name) {
70
+ this.activeEvents = [] // events that are currently processing
71
+ this.listeners = [] // event listeners
72
+ // register globally
73
+ if (typeof name !== 'undefined') {
74
+ if (!w2utils.checkName(name)) return
75
+ w2ui[name] = this
76
+ }
77
+ this.debug = false // if true, will trigger all events
78
+ }
79
+
80
+ /**
81
+ * Adds event listener, supports event phase and event scoping
82
+ *
83
+ * @param {*} edata - an object or string, if string "eventName:phase.scope"
84
+ * @param {*} handler
85
+ * @returns itself
86
+ */
87
+ on(events, handler) {
88
+ if (typeof events == 'string') {
89
+ events = events.split(/[,\s]+/) // separate by comma or space
90
+ } else {
91
+ events = [events]
92
+ }
93
+ events.forEach(edata => {
94
+ let name = typeof edata == 'string' ? edata : (edata.type + ':' + edata.execute + '.' + edata.scope)
95
+ if (typeof edata == 'string') {
96
+ let [eventName, scope] = edata.split('.')
97
+ let [type, execute] = eventName.replace(':complete', ':after').replace(':done', ':after').split(':')
98
+ edata = { type, execute: execute ?? 'before', scope }
99
+ }
100
+ edata = w2utils.extend({ type: null, execute: 'before', onComplete: null }, edata)
101
+ // errors
102
+ if (!edata.type) { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return }
103
+ if (!handler) { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return }
104
+ if (!Array.isArray(this.listeners)) this.listeners = []
105
+ this.listeners.push({ name, edata, handler })
106
+ if (this.debug) {
107
+ console.log('w2base: add event', { name, edata, handler })
108
+ }
109
+ })
110
+ return this
111
+ }
112
+
113
+ /**
114
+ * Removes event listener, supports event phase and event scoping
115
+ *
116
+ * @param {*} edata - an object or string, if string "eventName:phase.scope"
117
+ * @param {*} handler
118
+ * @returns itself
119
+ */
120
+ off(events, handler) {
121
+ if (typeof events == 'string') {
122
+ events = events.split(/[,\s]+/) // separate by comma or space
123
+ } else {
124
+ events = [events]
125
+ }
126
+ events.forEach(edata => {
127
+ let name = typeof edata == 'string' ? edata : (edata.type + ':' + edata.execute + '.' + edata.scope)
128
+ if (typeof edata == 'string') {
129
+ let [eventName, scope] = edata.split('.')
130
+ let [type, execute] = eventName.replace(':complete', ':after').replace(':done', ':after').split(':')
131
+ edata = { type: type || '*', execute: execute || '', scope: scope || '' }
132
+ }
133
+ edata = w2utils.extend({ type: null, execute: null, onComplete: null }, edata)
134
+ // errors
135
+ if (!edata.type && !edata.scope) { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return }
136
+ if (!handler) { handler = null }
137
+ let count = 0
138
+ // remove listener
139
+ this.listeners = this.listeners.filter(curr => {
140
+ if ( (edata.type === '*' || edata.type === curr.edata.type)
141
+ && (edata.execute === '' || edata.execute === curr.edata.execute)
142
+ && (edata.scope === '' || edata.scope === curr.edata.scope)
143
+ && (edata.handler == null || edata.handler === curr.edata.handler)
144
+ ) {
145
+ count++ // how many listeners removed
146
+ return false
147
+ } else {
148
+ return true
149
+ }
150
+ })
151
+ if (this.debug) {
152
+ console.log(`w2base: remove event (${count})`, { name, edata, handler })
153
+ }
154
+ })
155
+ return this // needed for chaining
156
+ }
157
+
158
+ /**
159
+ * Triggers even listeners for a specific event, loops through this.listeners
160
+ *
161
+ * @param {Object} edata - Object
162
+ * @returns modified edata
163
+ */
164
+ trigger(eventName, edata) {
165
+ if (arguments.length == 1) {
166
+ if (typeof eventName == 'string') {
167
+ edata = { type: eventName, target: this }
168
+ } else {
169
+ edata = eventName
170
+ }
171
+ } else {
172
+ edata.type = eventName
173
+ edata.target = edata.target ?? this
174
+ }
175
+ if (w2utils.isPlainObject(edata) && edata.phase == 'after') {
176
+ // find event
177
+ edata = this.activeEvents.find(event => {
178
+ if (event.type == edata.type && event.target == edata.target) {
179
+ return true
180
+ }
181
+ return false
182
+ })
183
+ if (!edata) {
184
+ console.log(`ERROR: Cannot find even handler for "${edata.type}" on "${edata.target}".`)
185
+ return
186
+ }
187
+ console.log('NOTICE: This syntax "edata.trigger({ phase: \'after\' })" is outdated. Use edata.finish() instead.')
188
+ } else if (!(edata instanceof w2event)) {
189
+ edata = new w2event(this, edata)
190
+ this.activeEvents.push(edata)
191
+ }
192
+ let args, fun, tmp
193
+ if (!Array.isArray(this.listeners)) this.listeners = []
194
+ if (this.debug) {
195
+ console.log(`w2base: trigger "${edata.type}:${edata.phase}"`, edata)
196
+ }
197
+ // process events in REVERSE order
198
+ for (let h = this.listeners.length-1; h >= 0; h--) {
199
+ let item = this.listeners[h]
200
+ if (item != null && (item.edata.type === edata.type || item.edata.type === '*') &&
201
+ (item.edata.target === edata.target || item.edata.target == null) &&
202
+ (item.edata.execute === edata.phase || item.edata.execute === '*' || item.edata.phase === '*'))
203
+ {
204
+ // add extra params if there
205
+ Object.keys(item.edata).forEach(key => {
206
+ if (edata[key] == null && item.edata[key] != null) {
207
+ edata[key] = item.edata[key]
208
+ }
209
+ })
210
+ // check handler arguments
211
+ args = []
212
+ tmp = new RegExp(/\((.*?)\)/).exec(String(item.handler).split('=>')[0])
213
+ if (tmp) args = tmp[1].split(/\s*,\s*/)
214
+ if (args.length === 2) {
215
+ item.handler.call(this, edata.target, edata) // old way for back compatibility
216
+ if (this.debug) console.log(' - call (old)', item.handler)
217
+ } else {
218
+ item.handler.call(this, edata) // new way
219
+ if (this.debug) console.log(' - call', item.handler)
220
+ }
221
+ if (edata.isStopped === true || edata.stop === true) return edata // back compatibility edata.stop === true
222
+ }
223
+ }
224
+ // main object events
225
+ let funName = 'on' + edata.type.substr(0,1).toUpperCase() + edata.type.substr(1)
226
+ if (edata.phase === 'before' && typeof this[funName] === 'function') {
227
+ fun = this[funName]
228
+ // check handler arguments
229
+ args = []
230
+ tmp = new RegExp(/\((.*?)\)/).exec(String(fun).split('=>')[0])
231
+ if (tmp) args = tmp[1].split(/\s*,\s*/)
232
+ if (args.length === 2) {
233
+ fun.call(this, edata.target, edata) // old way for back compatibility
234
+ if (this.debug) console.log(' - call: on[Event] (old)', fun)
235
+ } else {
236
+ fun.call(this, edata) // new way
237
+ if (this.debug) console.log(' - call: on[Event]', fun)
238
+ }
239
+ if (edata.isStopped === true || edata.stop === true) return edata // back compatibility edata.stop === true
240
+ }
241
+ // item object events
242
+ if (edata.object != null && edata.phase === 'before' && typeof edata.object[funName] === 'function') {
243
+ fun = edata.object[funName]
244
+ // check handler arguments
245
+ args = []
246
+ tmp = new RegExp(/\((.*?)\)/).exec(String(fun).split('=>')[0])
247
+ if (tmp) args = tmp[1].split(/\s*,\s*/)
248
+ if (args.length === 2) {
249
+ fun.call(this, edata.target, edata) // old way for back compatibility
250
+ if (this.debug) console.log(' - call: edata.object (old)', fun)
251
+ } else {
252
+ fun.call(this, edata) // new way
253
+ if (this.debug) console.log(' - call: edata.object', fun)
254
+ }
255
+ if (edata.isStopped === true || edata.stop === true) return edata
256
+ }
257
+ // execute onComplete
258
+ if (edata.phase === 'after') {
259
+ if (typeof edata.onComplete === 'function') edata.onComplete.call(this, edata)
260
+ for (let i = 0; i < edata.listeners.length; i++) {
261
+ if (typeof edata.listeners[i] === 'function') {
262
+ edata.listeners[i].call(this, edata)
263
+ if (this.debug) console.log(' - call: done', fun)
264
+ }
265
+ }
266
+ edata._resolve(edata)
267
+ if (this.debug) {
268
+ console.log(`w2base: trigger "${edata.type}:${edata.phase}"`, edata)
269
+ }
270
+ // clean up activeEvents
271
+ let ind = this.activeEvents.indexOf(edata)
272
+ if (ind !== -1) this.activeEvents.splice(ind, 1)
273
+ }
274
+ return edata
275
+ }
276
+
277
+ /**
278
+ * This method renders component into the box. It is overwritten in descendents and in this base
279
+ * component it is empty.
280
+ */
281
+ render(box) {
282
+ // intentionally left blank
283
+ }
284
+
285
+ /**
286
+ * Removes all classes that start with w2ui-* and sets box to null. It is needed so that control will
287
+ * release the box to be used for other widgets
288
+ */
289
+ unmount() {
290
+ let edata = this.trigger('unmount', { target: this.name })
291
+ if (edata.isCancelled) {
292
+ return
293
+ }
294
+ let remove = []
295
+ // find classes that start with "w2ui-*"
296
+ if (this.box instanceof HTMLElement) {
297
+ this.box.classList.forEach(cl => {
298
+ if (cl.startsWith('w2ui-')) remove.push(cl)
299
+ })
300
+ }
301
+ query(this.box)
302
+ .off() // removes all events attached to this box previously
303
+ .removeClass(remove)
304
+ .removeAttr('name')
305
+ .html('')
306
+ this.box = null
307
+ // event after
308
+ edata.finish()
309
+ }
310
+ }
311
+ export { w2event, w2base }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Part of w2ui 2.0 library
3
+ * - Dependencies: jQuery, w2ui.*
4
+ *
5
+ * This file provided compatibility for projects that conntinue to use jQuery. It extends jQuery with
6
+ * w2ui support, such as fn.w2grid, fn.w2form, ... fn.w2render, fn.w2destroy, fn.w2tag, etc
7
+ *
8
+ * It is not needed for projects that use ES6 module loading.
9
+ *
10
+ * == 2.0 changes
11
+ * - CSP - fixed inline events
12
+ */
13
+
14
+ import { w2locale } from './w2locale.js'
15
+ import { w2event, w2base } from './w2base.js'
16
+ import { w2ui, w2utils } from './w2utils.js'
17
+ import { query } from './query.js'
18
+ import { w2popup, w2alert, w2confirm, w2prompt, Dialog } from './w2popup.js'
19
+ import { w2field } from './w2field.js'
20
+ import { w2form } from './w2form.js'
21
+ import { w2grid } from './w2grid.js'
22
+ import { w2layout } from './w2layout.js'
23
+ import { w2sidebar } from './w2sidebar.js'
24
+ import { w2tabs } from './w2tabs.js'
25
+ import { w2toolbar } from './w2toolbar.js'
26
+ import { w2tooltip, w2color, w2menu, w2date, Tooltip } from './w2tooltip.js'
27
+
28
+ // Register jQuery plugins
29
+ (function($) {
30
+
31
+ // register globals if needed
32
+ let w2globals = function() {
33
+ (function (win, obj) {
34
+ Object.keys(obj).forEach(key => {
35
+ win[key] = obj[key]
36
+ })
37
+ })(window, {
38
+ w2ui, w2utils, query, w2locale, w2event, w2base,
39
+ w2popup, w2alert, w2confirm, w2prompt, Dialog,
40
+ w2tooltip, w2menu, w2color, w2date, Tooltip,
41
+ w2toolbar, w2sidebar, w2tabs, w2layout, w2grid, w2form, w2field
42
+ })
43
+ }
44
+ // if url has globals at the end, then register globals
45
+ let param = String(import.meta.url).split('?')[1] || ''
46
+ if (param == 'globals' || param.substr(0, 8) == 'globals=') {
47
+ w2globals()
48
+ }
49
+
50
+ // if jQuery is not defined, then exit
51
+ if (!$) return
52
+ $.w2globals = w2globals
53
+
54
+ $.fn.w2render = function(name) {
55
+ if ($(this).length > 0) {
56
+ if (typeof name === 'string' && w2ui[name]) w2ui[name].render($(this)[0])
57
+ if (typeof name === 'object') name.render($(this)[0])
58
+ }
59
+ }
60
+
61
+ $.fn.w2destroy = function(name) {
62
+ if (!name && this.length > 0) name = this.attr('name')
63
+ if (typeof name === 'string' && w2ui[name]) w2ui[name].destroy()
64
+ if (typeof name === 'object') name.destroy()
65
+ }
66
+
67
+ $.fn.w2field = function(type, options) {
68
+ // if without arguments - return the object
69
+ if (arguments.length === 0) {
70
+ let obj = $(this).data('w2field')
71
+ return obj
72
+ }
73
+ return this.each((index, el) => {
74
+ let obj = $(el).data('w2field')
75
+ // if object is not defined, define it
76
+ if (obj == null) {
77
+ obj = new w2field(type, options)
78
+ obj.render(el)
79
+ return obj
80
+ } else { // fully re-init
81
+ obj = new w2field(type, options)
82
+ obj.render(el)
83
+ return obj
84
+ }
85
+ return null
86
+ })
87
+ }
88
+
89
+ $.fn.w2form = function(options) { return proc.call(this, options, 'w2form') }
90
+ $.fn.w2grid = function(options) { return proc.call(this, options, 'w2grid') }
91
+ $.fn.w2layout = function(options) { return proc.call(this, options, 'w2layout') }
92
+ $.fn.w2sidebar = function(options) { return proc.call(this, options, 'w2sidebar') }
93
+ $.fn.w2tabs = function(options) { return proc.call(this, options, 'w2tabs') }
94
+ $.fn.w2toolbar = function(options) { return proc.call(this, options, 'w2toolbar') }
95
+
96
+ function proc(options, type) {
97
+ if ($.isPlainObject(options)) {
98
+ let obj
99
+ if (type == 'w2form') {
100
+ obj = new w2form(options)
101
+ if (this.find('.w2ui-field').length > 0) {
102
+ obj.formHTML = this.html()
103
+ }
104
+ }
105
+ if (type == 'w2grid') obj = new w2grid(options)
106
+ if (type == 'w2layout') obj = new w2layout(options)
107
+ if (type == 'w2sidebar') obj = new w2sidebar(options)
108
+ if (type == 'w2tabs') obj = new w2tabs(options)
109
+ if (type == 'w2toolbar') obj = new w2toolbar(options)
110
+ if ($(this).length !== 0) {
111
+ obj.render(this[0])
112
+ }
113
+ return obj
114
+ } else {
115
+ let obj = w2ui[$(this).attr('name')]
116
+ if (!obj) return null
117
+ if (arguments.length > 0) {
118
+ if (obj[options]) obj[options].apply(obj, Array.prototype.slice.call(arguments, 1))
119
+ return this
120
+ } else {
121
+ return obj
122
+ }
123
+ }
124
+ }
125
+
126
+ $.fn.w2popup = function(options) {
127
+ if (this.length > 0 ) {
128
+ w2popup.template(this[0], null, options)
129
+ } else if (options.url) {
130
+ w2popup.load(options)
131
+ }
132
+ }
133
+
134
+ $.fn.w2marker = function() {
135
+ let str = Array.from(arguments)
136
+ if (Array.isArray(str[0])) str = str[0]
137
+ return $(this).each((index, el) => {
138
+ w2utils.marker(el, str)
139
+ })
140
+ }
141
+
142
+ $.fn.w2tag = function(text, options) {
143
+ return this.each((index, el) => {
144
+ if (text == null && options == null) {
145
+ w2tooltip.hide()
146
+ return
147
+ }
148
+ if (typeof text == 'object') {
149
+ options = text
150
+ } else {
151
+ options = options ?? {}
152
+ options.html = text
153
+ }
154
+ w2tooltip.show({ anchor: el, ...options })
155
+ })
156
+ }
157
+
158
+ $.fn.w2overlay = function(html, options) {
159
+ return this.each((index, el) => {
160
+ if (html == null && options == null) {
161
+ w2tooltip.hide()
162
+ return
163
+ }
164
+ if (typeof html == 'object') {
165
+ options = html
166
+ } else {
167
+ options.html = html
168
+ }
169
+ Object.assign(options, {
170
+ class: 'w2ui-white',
171
+ hideOn: ['doc-click']
172
+ })
173
+ w2tooltip.show({ anchor: el, ...options })
174
+ })
175
+ }
176
+
177
+ $.fn.w2menu = function(menu, options) {
178
+ return this.each((index, el) => {
179
+ if (typeof menu == 'object') {
180
+ options = menu
181
+ }
182
+ if (typeof menu == 'object') {
183
+ options = menu
184
+ } else {
185
+ options.items = menu
186
+ }
187
+ w2menu.show({ anchor: el, ...options })
188
+ })
189
+ }
190
+
191
+ $.fn.w2color = function(options, callBack) {
192
+ return this.each((index, el) => {
193
+ let tooltip = w2color.show({ anchor: el, ...options })
194
+ if (typeof callBack == 'function') {
195
+ tooltip.select(callBack)
196
+ }
197
+ })
198
+ }
199
+
200
+ })(window.jQuery)
201
+
202
+ export {
203
+ w2ui, w2utils, query, w2locale, w2event, w2base,
204
+ w2popup, w2alert, w2confirm, w2prompt, Dialog,
205
+ w2tooltip, w2menu, w2color, w2date, Tooltip,
206
+ w2toolbar, w2sidebar, w2tabs, w2layout, w2grid, w2form, w2field
207
+ }