@gramlot/gramlot 0.2.18 → 0.2.19
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/dist/gramlot.js +74 -4
- package/dist/gramlot.min.js +11 -11
- package/package.json +1 -1
- package/src/binding/installation.js +4 -2
- package/src/builder/binding.json +26 -1
- package/src/builder/gramlot-builder.js +10 -0
- package/src/view/button.js +37 -2
package/package.json
CHANGED
|
@@ -171,7 +171,8 @@ export function requireInstallable(branch) {
|
|
|
171
171
|
|
|
172
172
|
// Provider attributes (§4.8): only a `dataFormula`, a `dataController`, a `dataRpc` or a `dataRemote`
|
|
173
173
|
// carries them; the lifecycle attributes not a `dataRemote`, whose resolver loads when its Data is read;
|
|
174
|
-
// the callbacks of the call only a `dataRpc`.
|
|
174
|
+
// the callbacks of the call only a `dataRpc`. `_delay` also belongs to Gramlot buttons
|
|
175
|
+
// and rendered ancestors that supply their inherited click delay.
|
|
175
176
|
const PROVIDER_ATTRIBUTES = ['_init', '_onStart', '_onBuilt', '_delay', '_timing', '_userChanges'];
|
|
176
177
|
const PROVIDER_TAGS = new Set(['dataFormula', 'dataController', 'dataRpc', 'dataRemote']);
|
|
177
178
|
const RPC_ATTRIBUTES = ['_onCalling', '_onResult', '_onError'];
|
|
@@ -208,7 +209,8 @@ function requireProviderAttributes(node) {
|
|
|
208
209
|
}
|
|
209
210
|
return;
|
|
210
211
|
}
|
|
211
|
-
const name = PROVIDER_ATTRIBUTES.find(isSet)
|
|
212
|
+
const name = PROVIDER_ATTRIBUTES.find(name => isSet(name)
|
|
213
|
+
&& !(name === '_delay' && !node._getMeta('data_element') && node.nodeTag !== 'html_button'));
|
|
212
214
|
if (!name) return;
|
|
213
215
|
const tags = LIFECYCLE_ATTRIBUTES.includes(name) ? 'dataFormula, dataController and dataRpc'
|
|
214
216
|
: 'dataFormula, dataController, dataRpc and dataRemote';
|
package/src/builder/binding.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "binding",
|
|
8
8
|
"version": null,
|
|
9
9
|
"title": "Gramlot binding",
|
|
10
|
-
"description": "Data
|
|
10
|
+
"description": "Gramlot Data declarations and the plain HTML button; loaded after the HTML grammar."
|
|
11
11
|
},
|
|
12
12
|
"abstracts": {},
|
|
13
13
|
"elements": {
|
|
@@ -374,6 +374,31 @@
|
|
|
374
374
|
"_meta": {
|
|
375
375
|
"data_element": true
|
|
376
376
|
}
|
|
377
|
+
},
|
|
378
|
+
"html_button": {
|
|
379
|
+
"doc": "Plain native HTML button without Gramlot click mechanisms.",
|
|
380
|
+
"sub_tags": "a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",
|
|
381
|
+
"parent_tags": null,
|
|
382
|
+
"inherits_from": null,
|
|
383
|
+
"ns": null,
|
|
384
|
+
"attributes": {
|
|
385
|
+
"parameters": [
|
|
386
|
+
{
|
|
387
|
+
"name": "kwargs",
|
|
388
|
+
"kind": "var_keyword",
|
|
389
|
+
"role": "attribute",
|
|
390
|
+
"annotation": null,
|
|
391
|
+
"has_default": false
|
|
392
|
+
}
|
|
393
|
+
],
|
|
394
|
+
"accepts_var_keyword": true,
|
|
395
|
+
"accepts_var_positional": false
|
|
396
|
+
},
|
|
397
|
+
"node_label": null,
|
|
398
|
+
"collection_key": null,
|
|
399
|
+
"_meta": {
|
|
400
|
+
"render_tag": "button"
|
|
401
|
+
}
|
|
377
402
|
}
|
|
378
403
|
}
|
|
379
404
|
}
|
|
@@ -31,6 +31,10 @@ const DATA_INLINE_ATTRIBUTES = {dataFormula: 'formula', dataController: 'script'
|
|
|
31
31
|
|
|
32
32
|
/** The P18 violation of a data-element's attributes, or null. */
|
|
33
33
|
function dataElementError(tag, attrs) {
|
|
34
|
+
if (tag === 'html_button' && Object.keys(attrs).some(name =>
|
|
35
|
+
['action', 'ask', '_delay', 'fire'].includes(name) || name.startsWith('fire_'))) {
|
|
36
|
+
return 'plain HTML button: use button for action, ask, fire or _delay';
|
|
37
|
+
}
|
|
34
38
|
if (Object.hasOwn(attrs, 'ask') && tag !== 'button') return "'ask' is supported on buttons";
|
|
35
39
|
if (Object.hasOwn(attrs, '_ask') && !['dataController', 'dataFormula', 'dataRpc'].includes(tag)) return "'_ask' requires a controller, formula or RPC";
|
|
36
40
|
if (['dataSetter', 'dataRemote'].includes(tag) && Object.keys(attrs).some(name => name.startsWith('subscribe_') || name.startsWith('selfsubscribe_'))) {
|
|
@@ -154,6 +158,12 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
154
158
|
return super.validateNode(node, options);
|
|
155
159
|
}
|
|
156
160
|
|
|
161
|
+
/** Both button declarations occupy the native button slot in HTML content models. */
|
|
162
|
+
_validateChildren(parentTag, info, tags, includeMinimum) {
|
|
163
|
+
return super._validateChildren(parentTag, info,
|
|
164
|
+
tags.map(tag => tag === 'html_button' ? 'button' : tag), includeMinimum);
|
|
165
|
+
}
|
|
166
|
+
|
|
157
167
|
/** Custom elements are outside the native HTML child catalogue, as components are. */
|
|
158
168
|
_countsForGrammar(info) {
|
|
159
169
|
return info !== this.schema.webcomponent && super._countsForGrammar(info);
|
package/src/view/button.js
CHANGED
|
@@ -15,11 +15,13 @@ import {XHTML_NS} from '../renderer/attributes.js';
|
|
|
15
15
|
export class ButtonBinding {
|
|
16
16
|
#binding;
|
|
17
17
|
#record;
|
|
18
|
+
#cancelDelay = null;
|
|
19
|
+
#pendingCount = 0;
|
|
18
20
|
|
|
19
|
-
/** The
|
|
21
|
+
/** The binding of a Gramlot button; html_button remains native despite its DOM tag. */
|
|
20
22
|
static for(binding, record) {
|
|
21
23
|
const element = record.element;
|
|
22
|
-
if (element?.namespaceURI !== XHTML_NS || element.localName !== 'button') return null;
|
|
24
|
+
if (binding.node.nodeTag !== 'button' || element?.namespaceURI !== XHTML_NS || element.localName !== 'button') return null;
|
|
23
25
|
return new ButtonBinding(binding, record);
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -79,6 +81,7 @@ export class ButtonBinding {
|
|
|
79
81
|
|
|
80
82
|
detach() {
|
|
81
83
|
this.element.removeEventListener('click', this);
|
|
84
|
+
this.#cancelDelay?.();
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
handleEvent(event) {
|
|
@@ -97,6 +100,38 @@ export class ButtonBinding {
|
|
|
97
100
|
event.stopPropagation();
|
|
98
101
|
if (this.element.disabled) return;
|
|
99
102
|
const counter = this.binding.countClick();
|
|
103
|
+
// Legacy reads inherited _delay. An explicit zero overrides an ancestor's delay.
|
|
104
|
+
let owner = this.node;
|
|
105
|
+
while (owner && owner.getAttr('_delay') == null) owner = owner.parentNode;
|
|
106
|
+
const delay = owner ? owner.builder.runtimeValues(owner)[1]._delay : 0;
|
|
107
|
+
if (delay > 0) {
|
|
108
|
+
const count = this.#pendingCount + 1;
|
|
109
|
+
this.#cancelDelay?.();
|
|
110
|
+
this.#pendingCount = count;
|
|
111
|
+
const timer = setTimeout(() => {
|
|
112
|
+
release();
|
|
113
|
+
this.#cancelDelay = null;
|
|
114
|
+
this.#pendingCount = 0;
|
|
115
|
+
this.#execute(event, count);
|
|
116
|
+
}, delay);
|
|
117
|
+
const release = this.binding.track(() => this.#cancelDelay?.());
|
|
118
|
+
this.#cancelDelay = () => {
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
release();
|
|
121
|
+
this.#cancelDelay = null;
|
|
122
|
+
this.#pendingCount = 0;
|
|
123
|
+
};
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.#cancelDelay?.();
|
|
127
|
+
return this.#execute(event, counter);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Deliver the last event once; arguments are read when the mechanism executes. */
|
|
131
|
+
#execute(event, counter) {
|
|
132
|
+
if (this.binding.closed || this.element.disabled) return;
|
|
133
|
+
const mechanism = this.mechanism;
|
|
134
|
+
if (!mechanism) return;
|
|
100
135
|
const node = this.node;
|
|
101
136
|
const modifiers = eventToString(event);
|
|
102
137
|
if (mechanism === 'controller') {
|