@tschk/moonshine-vue 0.0.0-stage → 0.4.49
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/README.md +521 -2
- package/package.json +62 -4
- package/src/app.ts +150 -0
- package/src/compiler-sfc.ts +1 -0
- package/src/context.ts +71 -0
- package/src/error-context.ts +107 -0
- package/src/errors.ts +24 -0
- package/src/events.ts +114 -0
- package/src/expose.ts +123 -0
- package/src/framework.ts +1 -0
- package/src/index.ts +42 -0
- package/src/lifecycle.ts +113 -0
- package/src/model-equality.ts +43 -0
- package/src/model-ssr.ts +39 -0
- package/src/model.ts +222 -0
- package/src/normalize.ts +111 -0
- package/src/props.ts +471 -0
- package/src/reactive.ts +1704 -0
- package/src/render.ts +365 -0
- package/src/select-ssr.ts +24 -0
- package/src/select.ts +159 -0
- package/src/set.ts +145 -0
- package/src/shims.d.ts +17 -0
- package/src/slots.ts +82 -0
- package/src/text.ts +56 -0
- package/src/vue.ts +11 -0
package/src/slots.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Compiler-private static default-slot transport; independent of declared props. */
|
|
2
|
+
import {
|
|
3
|
+
getComponentContext,
|
|
4
|
+
withComponentConsumer,
|
|
5
|
+
} from "@tschk/moonshine-dom/component";
|
|
6
|
+
import {
|
|
7
|
+
createComponentScope,
|
|
8
|
+
runWithOwner,
|
|
9
|
+
untrack,
|
|
10
|
+
} from "@tschk/moonshine-dom/reactive";
|
|
11
|
+
import type { DOMChild } from "@tschk/moonshine-dom";
|
|
12
|
+
import type { SSRChild } from "@tschk/moonshine-dom/ssr";
|
|
13
|
+
const slots = /* @__PURE__ */ Symbol("moonshine.vue.slots");
|
|
14
|
+
type Content = () => unknown;
|
|
15
|
+
/** Each authored outlet gets a distinct instance; its factory identity is static. */
|
|
16
|
+
function createSlotOutlet(
|
|
17
|
+
source: object,
|
|
18
|
+
persistentDOM: boolean,
|
|
19
|
+
): (fallback?: Content) => unknown {
|
|
20
|
+
const consumer = getComponentContext();
|
|
21
|
+
const supplied = Reflect.get(source, slots, source) as Content | undefined;
|
|
22
|
+
if (supplied !== undefined && typeof supplied !== "function")
|
|
23
|
+
throw new TypeError("Slot content must be a factory");
|
|
24
|
+
let initialized = false,
|
|
25
|
+
result: unknown;
|
|
26
|
+
return (fallback) => {
|
|
27
|
+
if (consumer.owner.disposed) return undefined;
|
|
28
|
+
if (!initialized) {
|
|
29
|
+
const invoke = () =>
|
|
30
|
+
withComponentConsumer(consumer, () =>
|
|
31
|
+
untrack(() => (supplied ? supplied() : fallback?.())),
|
|
32
|
+
);
|
|
33
|
+
// Static DOM content outlives transient insert reads; SSR must retain its current attempt.
|
|
34
|
+
result = persistentDOM
|
|
35
|
+
? runWithOwner(consumer.owner, () => createComponentScope(invoke))
|
|
36
|
+
: invoke();
|
|
37
|
+
if (consumer.owner.disposed) return undefined;
|
|
38
|
+
initialized = true;
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createDOMSlotOutlet(
|
|
45
|
+
source: object,
|
|
46
|
+
): (fallback?: () => DOMChild) => DOMChild {
|
|
47
|
+
return createSlotOutlet(source, true) as (
|
|
48
|
+
fallback?: () => DOMChild,
|
|
49
|
+
) => DOMChild;
|
|
50
|
+
}
|
|
51
|
+
export function createServerSlotOutlet(
|
|
52
|
+
source: object,
|
|
53
|
+
): (fallback?: () => SSRChild) => SSRChild {
|
|
54
|
+
return createSlotOutlet(source, false) as (
|
|
55
|
+
fallback?: () => SSRChild,
|
|
56
|
+
) => SSRChild;
|
|
57
|
+
}
|
|
58
|
+
/** Compiler-private wrapper: native h creates its one consumer scope around this function. */
|
|
59
|
+
export function withDefaultSlot<P extends object, R>(
|
|
60
|
+
component: (props: P) => R,
|
|
61
|
+
content: Content,
|
|
62
|
+
): (props: P) => R {
|
|
63
|
+
if (typeof component !== "function" || typeof content !== "function")
|
|
64
|
+
throw new TypeError("Static component and slot factories required");
|
|
65
|
+
return (source) => {
|
|
66
|
+
const target = Object.create(
|
|
67
|
+
Object.getPrototypeOf(source),
|
|
68
|
+
Object.getOwnPropertyDescriptors(source),
|
|
69
|
+
);
|
|
70
|
+
Object.defineProperty(target, slots, {
|
|
71
|
+
value: content,
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
});
|
|
75
|
+
const view = new Proxy(target, {
|
|
76
|
+
get(_target, key) {
|
|
77
|
+
return key === slots ? content : Reflect.get(source, key, source);
|
|
78
|
+
},
|
|
79
|
+
}) as P;
|
|
80
|
+
return component(view);
|
|
81
|
+
};
|
|
82
|
+
}
|
package/src/text.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isRef } from "./reactive";
|
|
2
|
+
const baseString = Object.prototype.toString;
|
|
3
|
+
const object = (value: unknown): value is Record<string, unknown> =>
|
|
4
|
+
value !== null && typeof value === "object";
|
|
5
|
+
function symbolText(value: unknown, fallback: string | number = ""): unknown {
|
|
6
|
+
return typeof value === "symbol"
|
|
7
|
+
? "Symbol(" + (value.description ?? fallback) + ")"
|
|
8
|
+
: value;
|
|
9
|
+
}
|
|
10
|
+
function jsonValue(_key: string, value: unknown): unknown {
|
|
11
|
+
if (isRef(value)) return jsonValue("", value.value);
|
|
12
|
+
if (baseString.call(value) === "[object Map]") {
|
|
13
|
+
const map = value as Map<unknown, unknown>,
|
|
14
|
+
label = `Map(${map.size})`,
|
|
15
|
+
entries: Record<string, unknown> = {};
|
|
16
|
+
let index = 0;
|
|
17
|
+
// Gather before coercing keys so iterator failures retain precedence.
|
|
18
|
+
const pairs = [...map.entries()];
|
|
19
|
+
// Concatenation deliberately preserves the default primitive hint for object keys.
|
|
20
|
+
for (const [key, item] of pairs)
|
|
21
|
+
entries[(symbolText(key, index++) as string) + " =>"] = item;
|
|
22
|
+
return { [label]: entries };
|
|
23
|
+
}
|
|
24
|
+
if (baseString.call(value) === "[object Set]") {
|
|
25
|
+
const set = value as Set<unknown>;
|
|
26
|
+
return {
|
|
27
|
+
[`Set(${set.size})`]: [...set.values()].map((item) => symbolText(item)),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === "symbol") return symbolText(value);
|
|
31
|
+
if (
|
|
32
|
+
object(value) &&
|
|
33
|
+
!Array.isArray(value) &&
|
|
34
|
+
baseString.call(value) !== "[object Object]"
|
|
35
|
+
)
|
|
36
|
+
return String(value);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
/** Opt-in native Vue interpolation conversion; no HTML is produced. */
|
|
40
|
+
export function toDisplayString(value: unknown): string | undefined {
|
|
41
|
+
if (typeof value === "string") return value;
|
|
42
|
+
if (value == null) return "";
|
|
43
|
+
if (
|
|
44
|
+
Array.isArray(value) ||
|
|
45
|
+
(object(value) &&
|
|
46
|
+
(value.toString === baseString || typeof value.toString !== "function"))
|
|
47
|
+
) {
|
|
48
|
+
if (isRef(value)) return toDisplayString(value.value);
|
|
49
|
+
return JSON.stringify(value, jsonValue, 2);
|
|
50
|
+
}
|
|
51
|
+
return String(value);
|
|
52
|
+
}
|
|
53
|
+
/** SSR interpolation stringifies the helper result before the renderer escapes it. */
|
|
54
|
+
export function toDisplayStringSSR(value: unknown): string {
|
|
55
|
+
return String(toDisplayString(value));
|
|
56
|
+
}
|