modal 0.2.0 → 0.3.1

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.
package/package.json CHANGED
@@ -1,22 +1,49 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.2.0",
4
- "description": "A modal window for the browser.",
5
- "main": "modal.js",
3
+ "version": "0.3.1",
4
+ "description": "Modal client library for JavaScript",
5
+ "license": "MIT",
6
+ "homepage": "https://modal.com/docs",
7
+ "repository": "github:modal-labs/libmodal",
8
+ "bugs": "https://github.com/modal-labs/libmodal/issues",
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "files": [
12
+ "/dist"
13
+ ],
14
+ "main": "dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "types": "dist/index.d.ts",
22
+ "module": "dist/index.js",
6
23
  "scripts": {
7
- "test": "node_modules/.bin/mocha/ -R spec test"
24
+ "build": "tsup",
25
+ "check": "tsc",
26
+ "format": "prettier --write .",
27
+ "format:check": "prettier --check .",
28
+ "prepare": "scripts/gen-proto.sh",
29
+ "test": "vitest"
8
30
  },
9
- "repository": {
10
- "type": "git",
11
- "url": "git://github.com/bengourley/modal.js.git"
31
+ "dependencies": {
32
+ "long": "^5.3.1",
33
+ "nice-grpc": "^2.1.12",
34
+ "protobufjs": "^7.5.0",
35
+ "smol-toml": "^1.3.3",
36
+ "uuid": "^11.1.0"
12
37
  },
13
- "author": "Ben Gourley",
14
- "license": "BSD",
15
38
  "devDependencies": {
16
- "jade": "~0.28.1",
17
- "jsdom": "~0.5.0",
18
- "mocha": "~1.8.1",
19
- "jadeify2": "0.0.3",
20
- "jquery": "~1.8.3"
39
+ "@types/node": "^22.15.2",
40
+ "grpc-tools": "^1.13.0",
41
+ "p-queue": "^8.1.0",
42
+ "prettier": "^3.5.3",
43
+ "ts-proto": "^2.7.0",
44
+ "tsup": "^8.4.0",
45
+ "tsx": "^4.19.3",
46
+ "typescript": "~5.8.3",
47
+ "vitest": "^3.1.2"
21
48
  }
22
49
  }
package/.jshintrc DELETED
@@ -1,41 +0,0 @@
1
- { "asi": true
2
- , "boss": true
3
- , "browser": true
4
- , "camelcase": true
5
- , "curly": false
6
- , "devel": false
7
- , "devel": true
8
- , "eqeqeq": true
9
- , "eqnull": true
10
- , "es5": false
11
- , "evil": false
12
- , "immed": false
13
- , "indent": 2
14
- , "jquery": true
15
- , "latedef": false
16
- , "laxbreak": true
17
- , "laxcomma": true
18
- , "maxcomplexity": 6
19
- , "maxdepth": 4
20
- , "maxstatements": 25
21
- , "newcap": true
22
- , "node": true
23
- , "noempty": false
24
- , "nonew": true
25
- , "predef":
26
- [ "describe"
27
- , "it"
28
- , "before"
29
- , "beforeEach"
30
- , "after"
31
- , "afterEach"
32
- ]
33
- , "quotmark": "single"
34
- , "smarttabs": true
35
- , "strict": false
36
- , "trailing": false
37
- , "undef": true
38
- , "unused": true
39
- , "-W079": true
40
- , "-W069": true
41
- }
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- .idea/**
package/Readme.md DELETED
@@ -1,47 +0,0 @@
1
- # Modal
2
-
3
- A modal window for the browser.
4
-
5
- This module provides generic modal dialog functionality
6
- for blocking the UI and obtaining user input.
7
-
8
- ## Note:
9
- You need to 'require' this module in a commonJS style environment, and
10
- you need to be able to require the things with the .jade extension. I use
11
- [browserify](https://github.com/substack/browserify) to do this.
12
-
13
-
14
- ## Usage
15
-
16
- ```
17
- modal([options])[.on('event')]
18
- ```
19
-
20
- ### Options
21
-
22
- - title (string)
23
- - content (jQuery DOM element / raw string)
24
- - buttons (array)
25
- - text (string) the button text
26
- - event (string) the event name to fire when the button is clicked
27
- - classname (string) the classname to apply to the button
28
- - keyCode (number) the keycode of a shortcut key for the button
29
- - clickOutsideToClose (boolean) whether a click event outside of the modal should close it
30
- - clickOutsideEvent (string) the name of the event to be triggered on clicks outside of the modal
31
-
32
- Events will be fired on the modal according to which button is clicked.
33
- Defaults are confirm/cancel, but these can be overriden in your options.
34
-
35
- ### Example
36
-
37
- ```js
38
- modal(
39
- { title: 'Delete object'
40
- , content: 'Are you sure you want to delete this object?'
41
- , buttons:
42
- [ { text: 'Don\'t delete', event: 'cancel', classname: '' }
43
- , { text: 'Delete', event: 'confirm', classname: 'danger' }
44
- ]
45
- })
46
- .on('confirm', deleteItem)
47
- ```
@@ -1,9 +0,0 @@
1
- .modal-overlay
2
- .modal-content.js-modal
3
- if (title)
4
- h1.modal-title #{title}
5
- .js-content
6
- if (buttons.length)
7
- .modal-controls
8
- each button in buttons
9
- button.btn.js-button(class=button.className) #{button.text}
package/modal-template.js DELETED
@@ -1,45 +0,0 @@
1
- var jade = require('jade/lib/runtime.js');module.exports = function anonymous(locals, attrs, escape, rethrow, merge) {
2
- attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
3
- var buf = [];
4
- with (locals || {}) {
5
- var interp;
6
- buf.push('<div class="modal-overlay"><div class="modal-content js-modal">');
7
- if ( (title))
8
- {
9
- buf.push('<h1 class="modal-title">' + escape((interp = title) == null ? '' : interp) + '</h1>');
10
- }
11
- buf.push('<div class="js-content"></div>');
12
- if ( (buttons.length))
13
- {
14
- buf.push('<div class="modal-controls">');
15
- // iterate buttons
16
- ;(function(){
17
- if ('number' == typeof buttons.length) {
18
-
19
- for (var $index = 0, $$l = buttons.length; $index < $$l; $index++) {
20
- var button = buttons[$index];
21
-
22
- buf.push('<button');
23
- buf.push(attrs({ "class": ('btn') + ' ' + ('js-button') + ' ' + (button.className) }, {"class":true}));
24
- buf.push('>' + escape((interp = button.text) == null ? '' : interp) + '</button>');
25
- }
26
-
27
- } else {
28
- var $$l = 0;
29
- for (var $index in buttons) {
30
- $$l++; var button = buttons[$index];
31
-
32
- buf.push('<button');
33
- buf.push(attrs({ "class": ('btn') + ' ' + ('js-button') + ' ' + (button.className) }, {"class":true}));
34
- buf.push('>' + escape((interp = button.text) == null ? '' : interp) + '</button>');
35
- }
36
-
37
- }
38
- }).call(this);
39
-
40
- buf.push('</div>');
41
- }
42
- buf.push('</div></div>');
43
- }
44
- return buf.join("");
45
- }
package/modal.js DELETED
@@ -1,203 +0,0 @@
1
- module.exports = modal
2
-
3
- /*
4
- * This module provides generic modal dialog functionality
5
- * for blocking the UI and obtaining user input.
6
- *
7
- * Usage:
8
- *
9
- * modal([options])
10
- * [.on('event')]...
11
- *
12
- * options:
13
- * - title (string)
14
- * - content (jQuery DOM element / raw string)
15
- * - buttons (array)
16
- * - text (string) the button text
17
- * - event (string) the event name to fire when the button is clicked
18
- * - className (string) the className to apply to the button
19
- * - keyCodes ([numbers]) the keycodes of shortcuts key for the button
20
- * - clickOutsideToClose (boolean) whether a click event outside of the modal should close it
21
- * - clickOutsideEvent (string) the name of the event to be triggered on clicks outside of the modal
22
- *
23
- * Events will be fired on the modal according to which button is clicked.
24
- * Defaults are confirm/cancel, but these can be overriden in your options.
25
- *
26
- * Example:
27
- *
28
- * modal(
29
- * { title: 'Delete object'
30
- * , content: 'Are you sure you want to delete this object?'
31
- * , buttons:
32
- * [ { text: 'Don\'t delete', event: 'cancel', className: '' }
33
- * , { text: 'Delete', event: 'confirm', className: 'danger' }
34
- * ]
35
- * })
36
- * .on('confirm', deleteItem)
37
- */
38
-
39
- var Emitter = require('events').EventEmitter
40
- , template = require('./modal-template')
41
-
42
- , defaults =
43
- { title: 'Are you sure?'
44
- , content: 'Please confirm this action.'
45
- , buttons:
46
- [ { text: 'Cancel', event: 'cancel', className: '', keyCodes: [ 27 ] }
47
- , { text: 'Confirm', event: 'confirm', className: 'btn-primary' }
48
- ]
49
- , clickOutsideToClose: true
50
- , clickOutsideEvent: 'cancel'
51
- , className: ''
52
- , fx: true // used for testing
53
- }
54
-
55
- function modal(options) {
56
- return new Modal($.extend({}, defaults, options))
57
- }
58
-
59
- function Modal(settings) {
60
-
61
- Emitter.call(this)
62
-
63
- var el = $(template(settings))
64
- , modal = el.find('.js-modal')
65
- , content = el.find('.js-content')
66
- , buttons = el.find('.js-button')
67
- , keys = {}
68
- , transitionFn = $.fn.transition ? 'transition' : 'animate'
69
-
70
- if (typeof settings.content === 'string') {
71
- content.append($('<p/>', { text: settings.content }))
72
- } else {
73
- content.append(settings.content)
74
- }
75
-
76
- modal.addClass(settings.className)
77
-
78
- // Cache the button shortcut keycodes
79
- $.each(settings.buttons, function (i, button) {
80
- if (!button.keyCodes) return
81
- $.each(button.keyCodes, function (n, keyCode) {
82
- keys[keyCode + ''] = i
83
- })
84
- })
85
-
86
- /*
87
- * Reposition the modal in the middle of the screen
88
- */
89
- function centre() {
90
- if (modal.outerHeight(true) < $(window).height()) {
91
- var diff = $(window).height() - modal.outerHeight(true)
92
- modal.css({ top: diff / 2 })
93
- }
94
- }
95
-
96
- /*
97
- * Remove a modal from the DOM
98
- * and tear down its related events
99
- */
100
- var removeModal = $.proxy(function () {
101
- var listenersWithCallback = 0
102
-
103
- $.each(this.listeners('beforeClose'), function(i, fn) {
104
- if (isFunctionWithArguments(fn)) {
105
- listenersWithCallback++
106
- }
107
- })
108
-
109
- if (listenersWithCallback > 0) {
110
- var currentCallsCount = 0
111
- , performClose = function() {
112
- if (++currentCallsCount === listenersWithCallback) {
113
- performRemoveModal()
114
- }
115
- }
116
- this.emit('beforeClose', performClose)
117
- } else {
118
- this.emit('beforeClose')
119
- performRemoveModal()
120
- }
121
- }, this)
122
-
123
- function isFunctionWithArguments(fn) {
124
- return fn.length > 0
125
- }
126
-
127
- var performRemoveModal = $.proxy(function () {
128
- el[transitionFn]({ opacity: 0 }, settings.fx ? 200 : 0)
129
- // Do setTimeout rather than using the transition
130
- // callback as it potentially fails to get called in IE10
131
- setTimeout(function () {
132
- el.remove()
133
- }, settings.fx ? 200 : 0)
134
- modal[transitionFn]({ top: $(window).height() }, settings.fx ? 200 : 0)
135
- this.emit('close')
136
- this.removeAllListeners()
137
- $(document).off('keyup', keyup)
138
- $(window).off('resize', centre)
139
- }, this)
140
-
141
- // Expose so you can control externally
142
- this.close = function() {
143
- removeModal()
144
- }
145
-
146
- // Expose so you can recentre externally
147
- this.centre = centre
148
-
149
- /*
150
- * Respond to a key event
151
- */
152
- var keyup = $.proxy(function (e) {
153
- var button = keys[e.keyCode + '']
154
- if (typeof button !== 'undefined') {
155
- this.emit(settings.buttons[button].event)
156
- removeModal()
157
- }
158
- }, this)
159
-
160
- // Assign button event handlers
161
- buttons.each($.proxy(function (i, el) {
162
- $(el).on('click', $.proxy(function () {
163
- this.emit(settings.buttons[i].event)
164
- removeModal()
165
- }, this))
166
- }, this))
167
-
168
- $(document).on('keyup', keyup)
169
-
170
- // Listen for clicks outside the modal
171
- el.on('click', $.proxy(function (e) {
172
- if ($(e.target).is(el)) {
173
- this.emit(settings.clickOutsideEvent)
174
- // Clicks outside should close?
175
- if (settings.clickOutsideToClose) {
176
- removeModal()
177
- }
178
- }
179
- }, this))
180
-
181
- // Set initial styles
182
- el.css({ opacity: 0 })
183
- modal.css({ top: '0%' })
184
-
185
- // Append to DOM
186
- $('body').append(el)
187
-
188
- // transition in
189
- el[transitionFn]({ opacity: 1 }, settings.fx ? 100 : 0)
190
-
191
- if (modal.outerHeight(true) < $(window).height()) {
192
- var diff = $(window).height() - modal.outerHeight(true)
193
- modal[transitionFn]({ top: (diff / 2) + 10 }, settings.fx ? 200 : 0, function () {
194
- modal[transitionFn]({ top: diff / 2 }, settings.fx ? 150 : 0)
195
- })
196
- }
197
-
198
- $(window).on('resize', centre)
199
-
200
- }
201
-
202
- // Be an emitter
203
- Modal.prototype = Emitter.prototype
package/pliers.js DELETED
@@ -1,18 +0,0 @@
1
- module.exports = tasks
2
-
3
- var jadeify = require('jadeify2')
4
- , join = require('path').join
5
- , fs = require('fs')
6
-
7
- function tasks(pliers) {
8
-
9
- pliers('build', function () {
10
-
11
- var readStream = fs.createReadStream(join(__dirname, 'modal-template.jade'))
12
- , writeSteam = fs.createWriteStream(join(__dirname, 'modal-template.js'))
13
-
14
- readStream.pipe(jadeify(join(__dirname, 'modal-template.jade'))).pipe(writeSteam)
15
-
16
- })
17
-
18
- }