marko 5.33.3 → 5.33.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/dist/runtime/helpers/tags-compat/dom-debug.js +1 -0
  2. package/dist/runtime/helpers/tags-compat/dom-debug.mjs +3 -0
  3. package/dist/runtime/helpers/tags-compat/dom.js +1 -0
  4. package/dist/runtime/helpers/tags-compat/dom.mjs +3 -0
  5. package/dist/runtime/helpers/tags-compat/html-debug.js +3 -0
  6. package/dist/runtime/helpers/tags-compat/html-debug.mjs +3 -0
  7. package/dist/runtime/helpers/tags-compat/html.js +1 -0
  8. package/dist/runtime/helpers/tags-compat/html.mjs +3 -0
  9. package/dist/runtime/helpers/tags-compat/runtime-dom.js +231 -0
  10. package/dist/runtime/helpers/tags-compat/runtime-html.js +171 -0
  11. package/dist/runtime/html/AsyncStream.js +12 -12
  12. package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
  13. package/dist/runtime/html/helpers/attr.js +3 -3
  14. package/dist/runtime/html/helpers/data-marko.js +1 -1
  15. package/dist/runtime/html/helpers/escape-quotes.js +1 -1
  16. package/dist/runtime/html/helpers/escape-xml.js +1 -1
  17. package/dist/runtime/renderable.js +3 -3
  18. package/dist/runtime/vdom/AsyncVDOMBuilder.js +67 -67
  19. package/dist/runtime/vdom/VComponent.js +3 -3
  20. package/dist/runtime/vdom/VDocumentFragment.js +7 -7
  21. package/dist/runtime/vdom/VElement.js +35 -35
  22. package/dist/runtime/vdom/VFragment.js +5 -5
  23. package/dist/runtime/vdom/VNode.js +30 -30
  24. package/dist/runtime/vdom/VText.js +8 -8
  25. package/dist/runtime/vdom/helpers/const-element.js +3 -3
  26. package/dist/runtime/vdom/hot-reload.js +2 -2
  27. package/dist/runtime/vdom/morphdom/fragment.js +3 -3
  28. package/dist/runtime/vdom/morphdom/helpers.js +1 -1
  29. package/dist/runtime/vdom/morphdom/index.js +31 -31
  30. package/dist/runtime/vdom/vdom.js +14 -14
  31. package/package.json +4 -4
  32. package/src/runtime/helpers/tags-compat/dom-debug.js +1 -0
  33. package/src/runtime/helpers/tags-compat/dom-debug.mjs +3 -0
  34. package/src/runtime/helpers/tags-compat/dom.js +1 -0
  35. package/src/runtime/helpers/tags-compat/dom.mjs +3 -0
  36. package/src/runtime/helpers/tags-compat/html-debug.js +3 -0
  37. package/src/runtime/helpers/tags-compat/html-debug.mjs +3 -0
  38. package/src/runtime/helpers/tags-compat/html.js +1 -0
  39. package/src/runtime/helpers/tags-compat/html.mjs +3 -0
  40. package/src/runtime/helpers/tags-compat/runtime-dom.js +231 -0
  41. package/src/runtime/helpers/tags-compat/runtime-html.js +171 -0
  42. package/dist/runtime/helpers/tags-compat-dom.js +0 -276
  43. package/dist/runtime/helpers/tags-compat-html.js +0 -172
  44. package/src/runtime/helpers/tags-compat-dom.js +0 -276
  45. package/src/runtime/helpers/tags-compat-html.js +0 -172
@@ -1,276 +0,0 @@
1
- const { ___componentLookup } = require("@internal/components-util");
2
- const { ___getComponentsContext } = require("../components/ComponentsContext");
3
-
4
- const {
5
- prepare,
6
- runEffects,
7
- patchConditionals,
8
- createScopeWithRenderer,
9
- queueEffect,
10
- scopeLookup,
11
- getRegisteredWithScope,
12
- register,
13
- } = require(
14
- // eslint-disable-next-line no-constant-condition
15
- "MARKO_DEBUG" ? "@marko/runtime-tags/debug/dom" : "@marko/runtime-tags/dom",
16
- );
17
- const defineComponent = require("../components/defineComponent");
18
- const { r: registerComponent } = require("../components/registry");
19
- const createRenderer = require("../components/renderer");
20
- const defaultCreateOut = require("../createOut");
21
- const morphdom = require("../vdom/morphdom");
22
- const { ___createFragmentNode } = require("../vdom/morphdom/fragment");
23
- const dynamicTag = require("./dynamic-tag");
24
-
25
- dynamicTag.___runtimeCompat = function tagsToVdom(
26
- tagsRenderer,
27
- renderBody,
28
- args,
29
- ) {
30
- if (
31
- tagsRenderer
32
- ? tagsRenderer.___clone === undefined
33
- : !Array.isArray(renderBody) && renderBody?.___clone === undefined
34
- )
35
- return tagsRenderer;
36
-
37
- return (input, out) =>
38
- TagsCompat({ i: args ? args : input, r: tagsRenderer || renderBody }, out);
39
- };
40
-
41
- const TagsCompatId = "tags-compat";
42
- const TagsCompat = createRenderer(
43
- function (_, out, componentDef, component) {
44
- let existing = false;
45
- const isHydrate =
46
- ___getComponentsContext(out).___globalContext.___isHydrate;
47
- const input = Array.isArray(_.i) ? _.i : [_.i];
48
- const tagsRenderer = resolveRegistered(_.r);
49
- const args = tagsRenderer.___args;
50
-
51
- component.effects = prepare(() => {
52
- if (isHydrate) {
53
- const scopeId = out.global.componentIdToScopeId[component.id];
54
- component.scope = scopeLookup[scopeId];
55
- }
56
- if (!component.scope) {
57
- component.scope = createScopeWithRenderer(
58
- tagsRenderer /* out.global as context */,
59
- );
60
- for (const signal of tagsRenderer.___closureSignals) {
61
- signal(component.scope, true);
62
- }
63
- } else {
64
- args && args(component.scope, input, 1);
65
- existing = true;
66
- }
67
- args && args(component.scope, input);
68
- });
69
- out.bf(out.___assignedKey, component, existing);
70
- if (!existing) {
71
- out.node({
72
- ___actualize: () =>
73
- component.scope.___startNode === component.scope.___endNode
74
- ? component.scope.___startNode
75
- : component.scope.___startNode.parentNode,
76
- });
77
- }
78
- out.ef();
79
- },
80
- // eslint-disable-next-line no-constant-condition
81
- "MARKO_DEBUG"
82
- ? {
83
- t: TagsCompatId,
84
- d: true,
85
- }
86
- : {
87
- t: TagsCompatId,
88
- },
89
- {},
90
- );
91
-
92
- registerComponent(TagsCompatId, () => ({
93
- _: TagsCompat,
94
- Component: defineComponent(
95
- {
96
- onMount() {
97
- runEffects(this.effects);
98
- },
99
- onUpdate() {
100
- runEffects(this.effects);
101
- },
102
- },
103
- TagsCompat,
104
- ),
105
- }));
106
-
107
- // (
108
- // nodeAccessor: Accessor,
109
- // dynamicTagAttrs?: IntersectionSignal,
110
- // intersection?: IntersectionSignal,
111
- // valueWithIntersection?: ValueSignal
112
- // )
113
-
114
- const rendererCache = new WeakMap();
115
-
116
- patchConditionals((conditional) => (...args) => {
117
- const signal = conditional(...args);
118
- const hasAttrs = args.length > 1;
119
- return (scope, renderer, clean) => {
120
- return signal(scope, create5to6Renderer(renderer, hasAttrs), clean);
121
- };
122
- });
123
-
124
- function create5to6Renderer(renderer, hasAttrs) {
125
- let newRenderer = renderer;
126
- if (renderer) {
127
- const rendererFromAnywhere =
128
- renderer._ ||
129
- renderer.render ||
130
- (renderer.renderer && renderer.renderer.renderer) ||
131
- renderer.renderer;
132
- const isMarko6 = rendererFromAnywhere
133
- ? rendererFromAnywhere.___clone
134
- : renderer.___clone;
135
-
136
- if (typeof renderer !== "string" && !isMarko6) {
137
- newRenderer = rendererCache.get(renderer);
138
- if (!newRenderer) {
139
- const { Component } = renderer;
140
- if (Component) {
141
- const setCustomEvents = Component.prototype.___setCustomEvents;
142
- Component.prototype.___setCustomEvents = function (
143
- customEvents,
144
- scopeId,
145
- ) {
146
- for (const customEvent of customEvents) {
147
- customEvent[1] = resolveRegistered(customEvent[1]);
148
- }
149
-
150
- setCustomEvents.call(this, customEvents, scopeId);
151
- };
152
- }
153
- newRenderer = {
154
- ___setup(scope) {
155
- if (!hasAttrs) {
156
- renderAndMorph(scope, rendererFromAnywhere, renderer, {});
157
- }
158
- },
159
- ___clone() {
160
- const realFragment = document.createDocumentFragment();
161
- ___createFragmentNode(null, null, realFragment);
162
- return realFragment;
163
- },
164
- ___hasUserEffects: 1,
165
- ___args(scope, input, clean) {
166
- if (clean) return;
167
- renderAndMorph(scope, rendererFromAnywhere, renderer, input);
168
- },
169
- };
170
- rendererCache.set(renderer, newRenderer);
171
- }
172
- }
173
- }
174
- return newRenderer;
175
- }
176
-
177
- register("@marko/tags-compat-5-to-6", create5to6Renderer);
178
-
179
- function renderAndMorph(scope, renderer, renderBody, input) {
180
- const out = defaultCreateOut();
181
- let rootNode = scope.___startNode.fragment;
182
- if (!rootNode) {
183
- const component = (scope.marko5Component = ___componentLookup[scope.m5c]);
184
- rootNode = component.___rootNode;
185
- scope.___startNode = rootNode.startNode;
186
- scope.___endNode = rootNode.endNode;
187
- }
188
- const host = scope.___startNode;
189
- const existingComponent = scope.marko5Component;
190
- const componentsContext = ___getComponentsContext(out);
191
- const globalComponentsContext = componentsContext.___globalContext;
192
- let customEvents;
193
- globalComponentsContext.___rerenderComponent = existingComponent;
194
- out.sync();
195
- if (renderer) {
196
- const [rawInput] = input;
197
- const normalizedInput = {};
198
-
199
- for (const key in rawInput) {
200
- let value = rawInput[key];
201
- if (key.startsWith("on")) {
202
- const c = key[2];
203
- customEvents = customEvents || {};
204
- customEvents[(c === "-" ? "" : c.toLowerCase()) + key.slice(3)] = [
205
- value,
206
- ];
207
- } else {
208
- normalizedInput[key] = rawInput[key];
209
- }
210
- }
211
-
212
- renderer(normalizedInput, out);
213
- } else {
214
- RenderBodyComponent({ renderBody, args: input }, out);
215
- }
216
-
217
- queueEffect(scope, () => {
218
- const targetNode = out.___getOutput().___firstChild;
219
- morphdom(rootNode, targetNode, host, componentsContext);
220
- const componentDefs = componentsContext.___initComponents(
221
- getRootNode(host),
222
- );
223
- const component = componentDefs[0].___component;
224
- component.___rootNode = rootNode;
225
- component.___input = input[0];
226
- component.___customEvents = customEvents;
227
- scope.marko5Component = component;
228
- });
229
- }
230
-
231
- function getRootNode(el) {
232
- var cur = el;
233
- while (cur.parentNode) cur = cur.parentNode;
234
- return cur;
235
- }
236
-
237
- const RenderBodyComponentId = "renderbody-renderer";
238
- const RenderBodyComponent = createRenderer(
239
- function (input, out, _componentDef) {
240
- dynamicTag(
241
- out,
242
- input.renderBody,
243
- null,
244
- null,
245
- input.args,
246
- null,
247
- _componentDef,
248
- "0",
249
- );
250
- },
251
- // eslint-disable-next-line no-constant-condition
252
- "MARKO_DEBUG"
253
- ? {
254
- t: RenderBodyComponentId,
255
- i: true,
256
- d: true,
257
- }
258
- : {
259
- t: RenderBodyComponentId,
260
- i: true,
261
- },
262
- {},
263
- );
264
-
265
- registerComponent(RenderBodyComponentId, () => ({
266
- _: RenderBodyComponent,
267
- Component: defineComponent({}, RenderBodyComponent),
268
- }));
269
-
270
- function resolveRegistered(renderer) {
271
- if (!Array.isArray(renderer)) return renderer;
272
-
273
- const [registerId, scopeId] = renderer;
274
- const scope = scopeLookup[scopeId];
275
- return getRegisteredWithScope(registerId, scope);
276
- }
@@ -1,172 +0,0 @@
1
- const initComponentsTag = require("../../core-tags/components/init-components-tag");
2
- const { ___getComponentsContext } = require("../components/ComponentsContext");
3
-
4
- const tagsAPI = require(
5
- // eslint-disable-next-line no-constant-condition
6
- "MARKO_DEBUG" ? "@marko/runtime-tags/debug/html" : "@marko/runtime-tags/html",
7
- );
8
- const createRenderer = require("../components/renderer");
9
- const defaultCreateOut = require("../createOut");
10
- const dynamicTag5 = require("./dynamic-tag");
11
- const {
12
- patchDynamicTag,
13
- createRenderFn,
14
- fork,
15
- write,
16
- makeSerializable,
17
- register,
18
- writeScope,
19
- nextScopeId,
20
- getRegistryInfo,
21
- } = tagsAPI;
22
-
23
- const FN_TO_JSON = function () {
24
- // TODO: this should instead return an object that contains getRegistryInfo
25
- // then in the dom-compat, handle that object to lookup the function in the registry
26
- // (we also need to do this for events)
27
- return getRegistryInfo(this);
28
- };
29
-
30
- const isMarko6 = (fn) => !!fn.___isTagsAPI;
31
- const isMarko5 = (fn) => !fn.___isTagsAPI;
32
-
33
- dynamicTag5.___runtimeCompat = function tagsToVdom(
34
- tagsRenderer,
35
- renderBody,
36
- args,
37
- ) {
38
- if (tagsRenderer ? isMarko5(tagsRenderer) : isMarko5(renderBody))
39
- return tagsRenderer;
40
-
41
- if (!tagsRenderer && renderBody) {
42
- renderBody.toJSON = FN_TO_JSON;
43
- }
44
-
45
- return (input, out) =>
46
- TagsCompat(
47
- args
48
- ? { i: args, r: (args) => (tagsRenderer || renderBody)(...args) }
49
- : { i: input, r: tagsRenderer || renderBody },
50
- out,
51
- );
52
- };
53
-
54
- const TagsCompatId = "tags-compat";
55
- const TagsCompat = createRenderer(
56
- function (_, out, componentDef, component) {
57
- const input = _.i;
58
- const tagsRenderer = _.r;
59
- const renderFn = createRenderFn(tagsRenderer);
60
- const $global = out.global;
61
- const streamData = ($global.streamData = $global.streamData || {});
62
-
63
- $global.serializedGlobals = $global.serializedGlobals || {};
64
- $global.serializedGlobals.componentIdToScopeId = true;
65
- $global.componentIdToScopeId = $global.componentIdToScopeId || {};
66
- $global.componentIdToScopeId[component.id] = streamData.scopeId || 0;
67
- out.bf(out.___assignedKey, component, true);
68
- renderFn(out.beginAsync(), input, {}, streamData);
69
- out.ef();
70
- },
71
- // eslint-disable-next-line no-constant-condition
72
- "MARKO_DEBUG"
73
- ? {
74
- t: TagsCompatId,
75
- d: true,
76
- }
77
- : {
78
- t: TagsCompatId,
79
- },
80
- {},
81
- );
82
-
83
- patchDynamicTag(
84
- function getRenderer(tag) {
85
- const renderer = tag._ || tag.renderBody || tag;
86
- if (isMarko6(renderer)) return renderer;
87
-
88
- const renderer5 =
89
- tag._ ||
90
- tag.render ||
91
- (tag.renderer && tag.renderer.renderer) ||
92
- tag.renderer;
93
- const renderBody5 = tag.renderBody || tag;
94
-
95
- return (input, ...args) => {
96
- const out = defaultCreateOut();
97
- let customEvents;
98
-
99
- out.global.streamData = tagsAPI.$_streamData;
100
-
101
- if (renderer5) {
102
- const normalizedInput = {};
103
-
104
- for (const key in input) {
105
- let value = input[key];
106
- if (key.startsWith("on") && typeof value === "function") {
107
- const c = key[2];
108
- customEvents = customEvents || [];
109
- customEvents.push([
110
- (c === "-" ? "" : c.toLowerCase()) + key.slice(3),
111
- value,
112
- ]);
113
- value.toJSON = FN_TO_JSON;
114
- } else {
115
- normalizedInput[key] = input[key];
116
- }
117
- }
118
- renderer5(normalizedInput, out);
119
- } else {
120
- renderBody5(out, input, ...args);
121
- }
122
-
123
- const componentsContext = ___getComponentsContext(out);
124
- const component = componentsContext.___components[0];
125
- if (component) {
126
- component.___component.___customEvents = customEvents;
127
- writeScope(nextScopeId(), {
128
- m5c: component.id,
129
- });
130
- }
131
-
132
- initComponentsTag({}, out);
133
-
134
- let async;
135
- out.once("finish", (result) => {
136
- if (!async) {
137
- async = false;
138
- write(result.toString());
139
- }
140
- });
141
-
142
- out.end();
143
-
144
- if (async !== false) {
145
- async = true;
146
- fork(out, (result) => {
147
- write(result.toString());
148
- });
149
- }
150
- };
151
- },
152
- function createRenderer(renderFn) {
153
- renderFn.___isTagsAPI = true;
154
- return renderFn;
155
- },
156
- );
157
-
158
- function dummyCreate5to6Renderer() {}
159
-
160
- register(dummyCreate5to6Renderer, "@marko/tags-compat-5-to-6");
161
-
162
- exports.serialized5to6 = function serialized5to6(renderer, id) {
163
- const dummyRenderer = () => {};
164
- register(dummyRenderer, id);
165
- return makeSerializable(renderer, (s) =>
166
- s
167
- .value(dummyCreate5to6Renderer)
168
- .code("(")
169
- .value(dummyRenderer)
170
- .code(",!0)"),
171
- );
172
- };