@json-to-office/core-docx 2.0.0 → 2.1.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.
- package/dist/plugin/example/index.d.ts.map +1 -1
- package/dist/plugin/example/index.js +232 -318
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/plugin/example/plugin-demo.json +16 -93
- package/dist/plugin/example/weather.component.d.ts +73 -9
- package/dist/plugin/example/weather.component.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/plugin/example/columns-layout.component.d.ts +0 -29
- package/dist/plugin/example/columns-layout.component.d.ts.map +0 -1
- package/dist/plugin/example/eldermoor-census.component.d.ts +0 -32
- package/dist/plugin/example/eldermoor-census.component.d.ts.map +0 -1
- package/dist/plugin/example/nested-section.component.d.ts +0 -16
- package/dist/plugin/example/nested-section.component.d.ts.map +0 -1
- package/dist/plugin/example/text-space-after.component.d.ts +0 -22
- package/dist/plugin/example/text-space-after.component.d.ts.map +0 -1
|
@@ -12452,167 +12452,262 @@ function createDocumentGenerator(options) {
|
|
|
12452
12452
|
|
|
12453
12453
|
// src/plugin/example/weather.component.ts
|
|
12454
12454
|
import { Type as Type2 } from "@sinclair/typebox";
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12455
|
+
import { createComponent, createVersion } from "@json-to-office/core-docx";
|
|
12456
|
+
var WEATHER_API_HOSTS = [
|
|
12457
|
+
"https://geocoding-api.open-meteo.com",
|
|
12458
|
+
"https://api.open-meteo.com"
|
|
12459
|
+
];
|
|
12460
|
+
var GEOCODING_URL = "https://geocoding-api.open-meteo.com/v1/search";
|
|
12461
|
+
var FORECAST_URL = "https://api.open-meteo.com/v1/forecast";
|
|
12462
|
+
var REQUEST_TIMEOUT_MS = 8e3;
|
|
12463
|
+
var UnitsSchema = Type2.Optional(
|
|
12464
|
+
Type2.Union([Type2.Literal("metric"), Type2.Literal("imperial")], {
|
|
12465
|
+
default: "metric",
|
|
12466
|
+
description: "metric = \xB0C and km/h, imperial = \xB0F and mph"
|
|
12467
|
+
})
|
|
12468
|
+
);
|
|
12469
12469
|
var WeatherV1PropsSchema = Type2.Object(
|
|
12470
12470
|
{
|
|
12471
12471
|
city: Type2.String({
|
|
12472
|
-
|
|
12472
|
+
minLength: 1,
|
|
12473
|
+
description: 'City to look up, e.g. "Milan" or "Milan, Italy"'
|
|
12473
12474
|
}),
|
|
12474
|
-
units:
|
|
12475
|
-
Type2.Union([Type2.Literal("metric"), Type2.Literal("imperial")], {
|
|
12476
|
-
default: "metric",
|
|
12477
|
-
description: "Temperature units"
|
|
12478
|
-
})
|
|
12479
|
-
),
|
|
12475
|
+
units: UnitsSchema,
|
|
12480
12476
|
showDetails: Type2.Optional(
|
|
12481
12477
|
Type2.Boolean({
|
|
12482
12478
|
default: true,
|
|
12483
|
-
description: "Show
|
|
12479
|
+
description: "Show humidity, wind and pressure under the reading"
|
|
12484
12480
|
})
|
|
12485
12481
|
)
|
|
12486
12482
|
},
|
|
12487
|
-
{
|
|
12488
|
-
additionalProperties: false
|
|
12489
|
-
}
|
|
12483
|
+
{ additionalProperties: false }
|
|
12490
12484
|
);
|
|
12491
12485
|
var WeatherV2PropsSchema = Type2.Object(
|
|
12492
12486
|
{
|
|
12493
12487
|
city: Type2.String({
|
|
12494
|
-
|
|
12488
|
+
minLength: 1,
|
|
12489
|
+
description: 'City to look up, e.g. "Milan" or "Milan, Italy"'
|
|
12495
12490
|
}),
|
|
12496
|
-
units:
|
|
12497
|
-
Type2.Union([Type2.Literal("metric"), Type2.Literal("imperial")], {
|
|
12498
|
-
default: "metric",
|
|
12499
|
-
description: "Temperature units"
|
|
12500
|
-
})
|
|
12501
|
-
),
|
|
12491
|
+
units: UnitsSchema,
|
|
12502
12492
|
days: Type2.Optional(
|
|
12503
12493
|
Type2.Number({
|
|
12504
|
-
default:
|
|
12494
|
+
default: 3,
|
|
12505
12495
|
minimum: 1,
|
|
12506
|
-
maximum:
|
|
12507
|
-
description: "Number of forecast days (1-
|
|
12496
|
+
maximum: 7,
|
|
12497
|
+
description: "Number of forecast days (1-7)"
|
|
12508
12498
|
})
|
|
12509
12499
|
)
|
|
12510
12500
|
},
|
|
12511
|
-
{
|
|
12512
|
-
additionalProperties: false
|
|
12513
|
-
}
|
|
12501
|
+
{ additionalProperties: false }
|
|
12514
12502
|
);
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
}
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
|
|
12503
|
+
var WEATHER_CODES = {
|
|
12504
|
+
0: "Clear sky",
|
|
12505
|
+
1: "Mainly clear",
|
|
12506
|
+
2: "Partly cloudy",
|
|
12507
|
+
3: "Overcast",
|
|
12508
|
+
45: "Fog",
|
|
12509
|
+
48: "Depositing rime fog",
|
|
12510
|
+
51: "Light drizzle",
|
|
12511
|
+
53: "Moderate drizzle",
|
|
12512
|
+
55: "Dense drizzle",
|
|
12513
|
+
56: "Light freezing drizzle",
|
|
12514
|
+
57: "Dense freezing drizzle",
|
|
12515
|
+
61: "Slight rain",
|
|
12516
|
+
63: "Moderate rain",
|
|
12517
|
+
65: "Heavy rain",
|
|
12518
|
+
66: "Light freezing rain",
|
|
12519
|
+
67: "Heavy freezing rain",
|
|
12520
|
+
71: "Slight snow",
|
|
12521
|
+
73: "Moderate snow",
|
|
12522
|
+
75: "Heavy snow",
|
|
12523
|
+
77: "Snow grains",
|
|
12524
|
+
80: "Slight rain showers",
|
|
12525
|
+
81: "Moderate rain showers",
|
|
12526
|
+
82: "Violent rain showers",
|
|
12527
|
+
85: "Slight snow showers",
|
|
12528
|
+
86: "Heavy snow showers",
|
|
12529
|
+
95: "Thunderstorm",
|
|
12530
|
+
96: "Thunderstorm with slight hail",
|
|
12531
|
+
99: "Thunderstorm with heavy hail"
|
|
12532
|
+
};
|
|
12533
|
+
function describeCode(code) {
|
|
12534
|
+
return typeof code === "number" && WEATHER_CODES[code] ? WEATHER_CODES[code] : "Unknown conditions";
|
|
12535
|
+
}
|
|
12536
|
+
var WeatherLookupError = class extends Error {
|
|
12537
|
+
constructor(message) {
|
|
12538
|
+
super(message);
|
|
12539
|
+
this.name = "WeatherLookupError";
|
|
12540
|
+
}
|
|
12541
|
+
};
|
|
12542
|
+
async function getJson(url, what) {
|
|
12543
|
+
let response;
|
|
12544
|
+
try {
|
|
12545
|
+
response = await fetch(url, {
|
|
12546
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
12547
|
+
headers: { accept: "application/json" }
|
|
12548
|
+
});
|
|
12549
|
+
} catch (error) {
|
|
12550
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
12551
|
+
throw new WeatherLookupError(
|
|
12552
|
+
`Could not reach Open-Meteo for ${what}: ${reason}. In the playground, list ${WEATHER_API_HOSTS.join(" and ")} under this plugin's Network switch.`
|
|
12553
|
+
);
|
|
12554
|
+
}
|
|
12555
|
+
if (!response.ok) {
|
|
12556
|
+
throw new WeatherLookupError(
|
|
12557
|
+
`Open-Meteo answered ${response.status} for ${what}.`
|
|
12558
|
+
);
|
|
12559
|
+
}
|
|
12560
|
+
return response.json();
|
|
12561
|
+
}
|
|
12562
|
+
async function geocode(city) {
|
|
12563
|
+
const url = `${GEOCODING_URL}?name=${encodeURIComponent(city)}&count=1&language=en&format=json`;
|
|
12564
|
+
const body = await getJson(url, `"${city}"`);
|
|
12565
|
+
const first = body.results?.[0];
|
|
12566
|
+
if (!first || typeof first.latitude !== "number") {
|
|
12567
|
+
throw new WeatherLookupError(
|
|
12568
|
+
`Open-Meteo has no place called "${city}". Try adding a country, e.g. "${city}, Italy".`
|
|
12569
|
+
);
|
|
12570
|
+
}
|
|
12571
|
+
return {
|
|
12572
|
+
name: String(first.name ?? city),
|
|
12573
|
+
country: typeof first.country === "string" ? first.country : void 0,
|
|
12574
|
+
admin1: typeof first.admin1 === "string" ? first.admin1 : void 0,
|
|
12575
|
+
latitude: first.latitude,
|
|
12576
|
+
longitude: first.longitude,
|
|
12577
|
+
timezone: typeof first.timezone === "string" ? first.timezone : void 0
|
|
12578
|
+
};
|
|
12579
|
+
}
|
|
12580
|
+
function placeLabel(place) {
|
|
12581
|
+
return [place.name, place.admin1, place.country].filter(Boolean).join(", ");
|
|
12582
|
+
}
|
|
12583
|
+
function unitParams(units) {
|
|
12584
|
+
return units === "imperial" ? "&temperature_unit=fahrenheit&wind_speed_unit=mph&precipitation_unit=inch" : "";
|
|
12585
|
+
}
|
|
12586
|
+
async function fetchCurrent(place, units) {
|
|
12587
|
+
const url = `${FORECAST_URL}?latitude=${place.latitude}&longitude=${place.longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,surface_pressure,weather_code&timezone=auto${unitParams(units)}`;
|
|
12588
|
+
const body = await getJson(url, `weather in ${place.name}`);
|
|
12589
|
+
const current = body.current;
|
|
12590
|
+
if (!current || typeof current.temperature_2m !== "number") {
|
|
12591
|
+
throw new WeatherLookupError(
|
|
12592
|
+
`Open-Meteo returned no current reading for ${place.name}.`
|
|
12593
|
+
);
|
|
12594
|
+
}
|
|
12595
|
+
const round = (value, fallback = 0) => typeof value === "number" ? Math.round(value) : fallback;
|
|
12596
|
+
return {
|
|
12597
|
+
temperature: Math.round(current.temperature_2m),
|
|
12598
|
+
apparent: round(
|
|
12599
|
+
current.apparent_temperature,
|
|
12600
|
+
Math.round(current.temperature_2m)
|
|
12601
|
+
),
|
|
12602
|
+
conditions: describeCode(current.weather_code),
|
|
12603
|
+
humidity: round(current.relative_humidity_2m),
|
|
12604
|
+
windSpeed: round(current.wind_speed_10m),
|
|
12605
|
+
pressure: round(current.surface_pressure),
|
|
12606
|
+
observedAt: typeof current.time === "string" ? current.time : ""
|
|
12607
|
+
};
|
|
12608
|
+
}
|
|
12609
|
+
async function fetchForecast(place, units, days) {
|
|
12610
|
+
const url = `${FORECAST_URL}?latitude=${place.latitude}&longitude=${place.longitude}&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max&forecast_days=${days}&timezone=auto${unitParams(units)}`;
|
|
12611
|
+
const body = await getJson(url, `the forecast for ${place.name}`);
|
|
12612
|
+
const daily = body.daily;
|
|
12613
|
+
const dates = daily?.time;
|
|
12614
|
+
if (!Array.isArray(dates) || dates.length === 0) {
|
|
12615
|
+
throw new WeatherLookupError(
|
|
12616
|
+
`Open-Meteo returned no forecast for ${place.name}.`
|
|
12617
|
+
);
|
|
12618
|
+
}
|
|
12619
|
+
const at = (key, i) => daily?.[key]?.[i];
|
|
12620
|
+
return dates.slice(0, days).map((date, i) => ({
|
|
12621
|
+
date: String(date),
|
|
12622
|
+
high: Math.round(Number(at("temperature_2m_max", i) ?? 0)),
|
|
12623
|
+
low: Math.round(Number(at("temperature_2m_min", i) ?? 0)),
|
|
12624
|
+
conditions: describeCode(at("weather_code", i)),
|
|
12625
|
+
precipitation: Math.round(
|
|
12626
|
+
Number(at("precipitation_probability_max", i) ?? 0)
|
|
12627
|
+
)
|
|
12557
12628
|
}));
|
|
12558
12629
|
}
|
|
12630
|
+
function formatDay(iso) {
|
|
12631
|
+
const date = /* @__PURE__ */ new Date(`${iso}T00:00:00Z`);
|
|
12632
|
+
if (Number.isNaN(date.getTime())) return iso;
|
|
12633
|
+
return date.toLocaleDateString("en-GB", {
|
|
12634
|
+
weekday: "short",
|
|
12635
|
+
day: "numeric",
|
|
12636
|
+
month: "short",
|
|
12637
|
+
timeZone: "UTC"
|
|
12638
|
+
});
|
|
12639
|
+
}
|
|
12559
12640
|
var weatherComponent = createComponent({
|
|
12560
12641
|
name: "weather",
|
|
12561
12642
|
versions: {
|
|
12562
12643
|
"1.0.0": createVersion({
|
|
12563
12644
|
propsSchema: WeatherV1PropsSchema,
|
|
12564
|
-
description: "
|
|
12645
|
+
description: "Current weather for a city, fetched live from Open-Meteo (needs network access to api.open-meteo.com and geocoding-api.open-meteo.com)",
|
|
12565
12646
|
render: async ({ props, addWarning }) => {
|
|
12566
|
-
const
|
|
12567
|
-
|
|
12568
|
-
const
|
|
12569
|
-
|
|
12647
|
+
const units = props.units ?? "metric";
|
|
12648
|
+
const place = await geocode(props.city);
|
|
12649
|
+
const weather = await fetchCurrent(place, units);
|
|
12650
|
+
addWarning(`Fetched live weather from Open-Meteo`, {
|
|
12651
|
+
place: placeLabel(place),
|
|
12652
|
+
observedAt: weather.observedAt
|
|
12653
|
+
});
|
|
12654
|
+
const degrees = units === "imperial" ? "\xB0F" : "\xB0C";
|
|
12655
|
+
const speed = units === "imperial" ? "mph" : "km/h";
|
|
12570
12656
|
const components = [
|
|
12571
12657
|
{
|
|
12572
12658
|
name: "heading",
|
|
12573
|
-
props: {
|
|
12574
|
-
level: 3,
|
|
12575
|
-
text: `Weather in ${props.city}`
|
|
12576
|
-
}
|
|
12659
|
+
props: { level: 3, text: `Weather in ${placeLabel(place)}` }
|
|
12577
12660
|
},
|
|
12578
12661
|
{
|
|
12579
12662
|
name: "paragraph",
|
|
12580
12663
|
props: {
|
|
12581
|
-
text: `${weather.temperature}${
|
|
12664
|
+
text: `${weather.temperature}${degrees} \u2014 ${weather.conditions}`,
|
|
12582
12665
|
font: { bold: true, size: 14 }
|
|
12583
12666
|
}
|
|
12584
12667
|
}
|
|
12585
12668
|
];
|
|
12586
|
-
if (props.showDetails) {
|
|
12669
|
+
if (props.showDetails ?? true) {
|
|
12587
12670
|
components.push({
|
|
12588
12671
|
name: "list",
|
|
12589
12672
|
props: {
|
|
12590
12673
|
items: [
|
|
12674
|
+
`Feels like: ${weather.apparent}${degrees}`,
|
|
12591
12675
|
`Humidity: ${weather.humidity}%`,
|
|
12592
|
-
`Wind
|
|
12676
|
+
`Wind: ${weather.windSpeed} ${speed}`,
|
|
12593
12677
|
`Pressure: ${weather.pressure} hPa`
|
|
12594
12678
|
]
|
|
12595
12679
|
}
|
|
12596
12680
|
});
|
|
12597
12681
|
}
|
|
12682
|
+
components.push({
|
|
12683
|
+
name: "paragraph",
|
|
12684
|
+
props: {
|
|
12685
|
+
text: `Source: Open-Meteo${weather.observedAt ? `, observed ${weather.observedAt.replace("T", " ")}` : ""}`,
|
|
12686
|
+
font: { size: 8, italic: true }
|
|
12687
|
+
}
|
|
12688
|
+
});
|
|
12598
12689
|
return components;
|
|
12599
12690
|
}
|
|
12600
12691
|
}),
|
|
12601
12692
|
"2.0.0": createVersion({
|
|
12602
12693
|
propsSchema: WeatherV2PropsSchema,
|
|
12603
|
-
description: "Multi-day forecast
|
|
12694
|
+
description: "Multi-day forecast table for a city, fetched live from Open-Meteo",
|
|
12604
12695
|
render: async ({ props, addWarning }) => {
|
|
12605
|
-
const units = props.units
|
|
12606
|
-
const days = props.days
|
|
12607
|
-
const
|
|
12608
|
-
const forecast = await fetchForecast(
|
|
12609
|
-
addWarning("Fetched forecast
|
|
12610
|
-
|
|
12696
|
+
const units = props.units ?? "metric";
|
|
12697
|
+
const days = props.days ?? 3;
|
|
12698
|
+
const place = await geocode(props.city);
|
|
12699
|
+
const forecast = await fetchForecast(place, units, days);
|
|
12700
|
+
addWarning("Fetched live forecast from Open-Meteo", {
|
|
12701
|
+
place: placeLabel(place),
|
|
12702
|
+
days: forecast.length
|
|
12703
|
+
});
|
|
12704
|
+
const degrees = units === "imperial" ? "\xB0F" : "\xB0C";
|
|
12705
|
+
return [
|
|
12611
12706
|
{
|
|
12612
12707
|
name: "heading",
|
|
12613
12708
|
props: {
|
|
12614
12709
|
level: 3,
|
|
12615
|
-
text: `${
|
|
12710
|
+
text: `${forecast.length}-day forecast for ${placeLabel(place)}`
|
|
12616
12711
|
}
|
|
12617
12712
|
},
|
|
12618
12713
|
{
|
|
@@ -12621,53 +12716,37 @@ var weatherComponent = createComponent({
|
|
|
12621
12716
|
columns: [
|
|
12622
12717
|
{
|
|
12623
12718
|
header: { content: "Day" },
|
|
12624
|
-
cells: forecast.map((
|
|
12719
|
+
cells: forecast.map((day) => ({
|
|
12720
|
+
content: formatDay(day.date)
|
|
12721
|
+
}))
|
|
12722
|
+
},
|
|
12723
|
+
{
|
|
12724
|
+
header: { content: `High (${degrees})` },
|
|
12725
|
+
cells: forecast.map((day) => ({ content: String(day.high) }))
|
|
12625
12726
|
},
|
|
12626
12727
|
{
|
|
12627
|
-
header: { content: `
|
|
12628
|
-
cells: forecast.map((
|
|
12728
|
+
header: { content: `Low (${degrees})` },
|
|
12729
|
+
cells: forecast.map((day) => ({ content: String(day.low) }))
|
|
12629
12730
|
},
|
|
12630
12731
|
{
|
|
12631
|
-
header: { content:
|
|
12632
|
-
cells: forecast.map((
|
|
12732
|
+
header: { content: "Rain" },
|
|
12733
|
+
cells: forecast.map((day) => ({
|
|
12734
|
+
content: `${day.precipitation}%`
|
|
12735
|
+
}))
|
|
12633
12736
|
},
|
|
12634
12737
|
{
|
|
12635
12738
|
header: { content: "Conditions" },
|
|
12636
|
-
cells: forecast.map((
|
|
12739
|
+
cells: forecast.map((day) => ({ content: day.conditions }))
|
|
12637
12740
|
}
|
|
12638
12741
|
]
|
|
12639
12742
|
}
|
|
12640
|
-
}
|
|
12641
|
-
];
|
|
12642
|
-
return components;
|
|
12643
|
-
}
|
|
12644
|
-
})
|
|
12645
|
-
}
|
|
12646
|
-
});
|
|
12647
|
-
|
|
12648
|
-
// src/plugin/example/columns-layout.component.ts
|
|
12649
|
-
import { Type as Type3 } from "@sinclair/typebox";
|
|
12650
|
-
var ColumnsLayoutPropsSchema = Type3.Object(
|
|
12651
|
-
{},
|
|
12652
|
-
{
|
|
12653
|
-
additionalProperties: false
|
|
12654
|
-
}
|
|
12655
|
-
);
|
|
12656
|
-
var columnsLayoutComponent = createComponent({
|
|
12657
|
-
name: "columnsLayout",
|
|
12658
|
-
versions: {
|
|
12659
|
-
"1.0.0": createVersion({
|
|
12660
|
-
propsSchema: ColumnsLayoutPropsSchema,
|
|
12661
|
-
hasChildren: true,
|
|
12662
|
-
description: "Renders a list of components in a 2-column layout",
|
|
12663
|
-
render: async ({ children }) => {
|
|
12664
|
-
return [
|
|
12743
|
+
},
|
|
12665
12744
|
{
|
|
12666
|
-
name: "
|
|
12745
|
+
name: "paragraph",
|
|
12667
12746
|
props: {
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12747
|
+
text: "Source: Open-Meteo",
|
|
12748
|
+
font: { size: 8, italic: true }
|
|
12749
|
+
}
|
|
12671
12750
|
}
|
|
12672
12751
|
];
|
|
12673
12752
|
}
|
|
@@ -12675,91 +12754,6 @@ var columnsLayoutComponent = createComponent({
|
|
|
12675
12754
|
}
|
|
12676
12755
|
});
|
|
12677
12756
|
|
|
12678
|
-
// src/plugin/example/nested-section.component.ts
|
|
12679
|
-
import { Type as Type4 } from "@sinclair/typebox";
|
|
12680
|
-
var NestedSectionsSchema = Type4.Object(
|
|
12681
|
-
{},
|
|
12682
|
-
{
|
|
12683
|
-
additionalProperties: false
|
|
12684
|
-
}
|
|
12685
|
-
);
|
|
12686
|
-
var nestedSectionsComponent = createComponent({
|
|
12687
|
-
name: "nestedSections",
|
|
12688
|
-
versions: {
|
|
12689
|
-
"1.0.0": createVersion({
|
|
12690
|
-
propsSchema: NestedSectionsSchema,
|
|
12691
|
-
description: "Generates nested sections for embedding in documents",
|
|
12692
|
-
render: async () => {
|
|
12693
|
-
const components = [];
|
|
12694
|
-
components.push({
|
|
12695
|
-
name: "section",
|
|
12696
|
-
props: {
|
|
12697
|
-
meta: { title: "First level 1 section" }
|
|
12698
|
-
},
|
|
12699
|
-
children: [
|
|
12700
|
-
{
|
|
12701
|
-
name: "heading",
|
|
12702
|
-
props: { text: "First level 1 section", level: 1 }
|
|
12703
|
-
},
|
|
12704
|
-
{
|
|
12705
|
-
name: "heading",
|
|
12706
|
-
props: {
|
|
12707
|
-
text: "Level 2 heading of first level 1 section",
|
|
12708
|
-
level: 2
|
|
12709
|
-
}
|
|
12710
|
-
},
|
|
12711
|
-
{
|
|
12712
|
-
name: "paragraph",
|
|
12713
|
-
props: {
|
|
12714
|
-
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
|
12715
|
-
}
|
|
12716
|
-
},
|
|
12717
|
-
{
|
|
12718
|
-
name: "heading",
|
|
12719
|
-
props: {
|
|
12720
|
-
text: "Level 2 heading of first level 1 section",
|
|
12721
|
-
level: 2
|
|
12722
|
-
}
|
|
12723
|
-
},
|
|
12724
|
-
{
|
|
12725
|
-
name: "paragraph",
|
|
12726
|
-
props: {
|
|
12727
|
-
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
|
12728
|
-
}
|
|
12729
|
-
}
|
|
12730
|
-
]
|
|
12731
|
-
});
|
|
12732
|
-
components.push({
|
|
12733
|
-
name: "section",
|
|
12734
|
-
props: {
|
|
12735
|
-
meta: { title: "Second level 1 section" }
|
|
12736
|
-
},
|
|
12737
|
-
children: [
|
|
12738
|
-
{
|
|
12739
|
-
name: "heading",
|
|
12740
|
-
props: { text: "Second level 1 section", level: 1 }
|
|
12741
|
-
},
|
|
12742
|
-
{
|
|
12743
|
-
name: "heading",
|
|
12744
|
-
props: {
|
|
12745
|
-
text: "Level 2 heading of second level 1 section",
|
|
12746
|
-
level: 2
|
|
12747
|
-
}
|
|
12748
|
-
},
|
|
12749
|
-
{
|
|
12750
|
-
name: "paragraph",
|
|
12751
|
-
props: {
|
|
12752
|
-
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
|
12753
|
-
}
|
|
12754
|
-
}
|
|
12755
|
-
]
|
|
12756
|
-
});
|
|
12757
|
-
return components;
|
|
12758
|
-
}
|
|
12759
|
-
})
|
|
12760
|
-
}
|
|
12761
|
-
});
|
|
12762
|
-
|
|
12763
12757
|
// src/plugin/example/index.ts
|
|
12764
12758
|
init_themes();
|
|
12765
12759
|
import * as fs3 from "fs/promises";
|
|
@@ -12772,48 +12766,43 @@ var plugin_demo_default = {
|
|
|
12772
12766
|
$schema: "../../../../../output/examples/plugin-demo-schema.json",
|
|
12773
12767
|
name: "docx",
|
|
12774
12768
|
props: {
|
|
12775
|
-
title: "Plugin Demo"
|
|
12769
|
+
title: "Weather Plugin Demo"
|
|
12776
12770
|
},
|
|
12777
12771
|
children: [
|
|
12778
|
-
{
|
|
12779
|
-
name: "nestedSections",
|
|
12780
|
-
props: {}
|
|
12781
|
-
},
|
|
12782
12772
|
{
|
|
12783
12773
|
name: "section",
|
|
12784
12774
|
props: {
|
|
12785
12775
|
meta: {
|
|
12786
|
-
title: "
|
|
12776
|
+
title: "Today"
|
|
12787
12777
|
}
|
|
12788
12778
|
},
|
|
12789
12779
|
children: [
|
|
12790
12780
|
{
|
|
12791
12781
|
name: "heading",
|
|
12792
12782
|
props: {
|
|
12793
|
-
text: "
|
|
12783
|
+
text: "Today",
|
|
12794
12784
|
level: 1,
|
|
12795
|
-
spacing: {
|
|
12796
|
-
before: 0,
|
|
12797
|
-
after: 0
|
|
12798
|
-
}
|
|
12785
|
+
spacing: { before: 0, after: 0 }
|
|
12799
12786
|
}
|
|
12800
12787
|
},
|
|
12801
12788
|
{
|
|
12802
12789
|
name: "paragraph",
|
|
12803
12790
|
props: {
|
|
12804
|
-
content: "
|
|
12791
|
+
content: "Each block below is rendered by the weather plugin, which calls Open-Meteo while the document is generated."
|
|
12805
12792
|
}
|
|
12806
12793
|
},
|
|
12807
12794
|
{
|
|
12808
12795
|
name: "weather",
|
|
12796
|
+
version: "1.0.0",
|
|
12809
12797
|
props: {
|
|
12810
|
-
city: "
|
|
12798
|
+
city: "Milan",
|
|
12811
12799
|
units: "metric",
|
|
12812
12800
|
showDetails: true
|
|
12813
12801
|
}
|
|
12814
12802
|
},
|
|
12815
12803
|
{
|
|
12816
12804
|
name: "weather",
|
|
12805
|
+
version: "1.0.0",
|
|
12817
12806
|
props: {
|
|
12818
12807
|
city: "New York",
|
|
12819
12808
|
units: "imperial",
|
|
@@ -12826,97 +12815,25 @@ var plugin_demo_default = {
|
|
|
12826
12815
|
name: "section",
|
|
12827
12816
|
props: {
|
|
12828
12817
|
meta: {
|
|
12829
|
-
title: "
|
|
12818
|
+
title: "The week ahead"
|
|
12830
12819
|
}
|
|
12831
12820
|
},
|
|
12832
12821
|
children: [
|
|
12833
12822
|
{
|
|
12834
12823
|
name: "heading",
|
|
12835
12824
|
props: {
|
|
12836
|
-
text: "
|
|
12825
|
+
text: "The week ahead",
|
|
12837
12826
|
level: 1,
|
|
12838
|
-
spacing: {
|
|
12839
|
-
before: 0,
|
|
12840
|
-
after: 0
|
|
12841
|
-
}
|
|
12842
|
-
}
|
|
12843
|
-
},
|
|
12844
|
-
{
|
|
12845
|
-
name: "paragraph",
|
|
12846
|
-
props: {
|
|
12847
|
-
content: "Recent sales performance:"
|
|
12827
|
+
spacing: { before: 0, after: 0 }
|
|
12848
12828
|
}
|
|
12849
12829
|
},
|
|
12850
12830
|
{
|
|
12851
|
-
name: "
|
|
12852
|
-
|
|
12853
|
-
query: "SELECT * FROM sales ORDER BY date DESC",
|
|
12854
|
-
title: "Q1 Sales Report",
|
|
12855
|
-
showRowNumbers: true,
|
|
12856
|
-
maxRows: 10
|
|
12857
|
-
}
|
|
12858
|
-
}
|
|
12859
|
-
]
|
|
12860
|
-
},
|
|
12861
|
-
{
|
|
12862
|
-
name: "section",
|
|
12863
|
-
props: {
|
|
12864
|
-
meta: {
|
|
12865
|
-
title: "Quick Links"
|
|
12866
|
-
}
|
|
12867
|
-
},
|
|
12868
|
-
children: [
|
|
12869
|
-
{
|
|
12870
|
-
name: "heading",
|
|
12871
|
-
props: {
|
|
12872
|
-
text: "Quick Links",
|
|
12873
|
-
level: 1,
|
|
12874
|
-
spacing: {
|
|
12875
|
-
before: 0,
|
|
12876
|
-
after: 0
|
|
12877
|
-
}
|
|
12878
|
-
}
|
|
12879
|
-
},
|
|
12880
|
-
{
|
|
12881
|
-
name: "paragraph",
|
|
12882
|
-
props: {
|
|
12883
|
-
content: "Scan these QR codes to access our resources:"
|
|
12884
|
-
}
|
|
12885
|
-
}
|
|
12886
|
-
]
|
|
12887
|
-
},
|
|
12888
|
-
{
|
|
12889
|
-
name: "section",
|
|
12890
|
-
props: {
|
|
12891
|
-
meta: {
|
|
12892
|
-
title: "More Data Examples"
|
|
12893
|
-
}
|
|
12894
|
-
},
|
|
12895
|
-
children: [
|
|
12896
|
-
{
|
|
12897
|
-
name: "heading",
|
|
12898
|
-
props: {
|
|
12899
|
-
text: "More Data Examples",
|
|
12900
|
-
level: 1,
|
|
12901
|
-
spacing: {
|
|
12902
|
-
before: 0,
|
|
12903
|
-
after: 0
|
|
12904
|
-
}
|
|
12905
|
-
}
|
|
12906
|
-
},
|
|
12907
|
-
{
|
|
12908
|
-
name: "dataTable",
|
|
12909
|
-
props: {
|
|
12910
|
-
query: 'SELECT * FROM users WHERE role = "Admin"',
|
|
12911
|
-
title: "System Administrators"
|
|
12912
|
-
}
|
|
12913
|
-
},
|
|
12914
|
-
{
|
|
12915
|
-
name: "dataTable",
|
|
12831
|
+
name: "weather",
|
|
12832
|
+
version: "2.0.0",
|
|
12916
12833
|
props: {
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12834
|
+
city: "Tokyo",
|
|
12835
|
+
units: "metric",
|
|
12836
|
+
days: 5
|
|
12920
12837
|
}
|
|
12921
12838
|
}
|
|
12922
12839
|
]
|
|
@@ -12934,7 +12851,7 @@ async function runPluginDemo() {
|
|
|
12934
12851
|
theme: minimalTheme,
|
|
12935
12852
|
debug: true
|
|
12936
12853
|
// Enable debug logging
|
|
12937
|
-
}).addComponent(weatherComponent)
|
|
12854
|
+
}).addComponent(weatherComponent);
|
|
12938
12855
|
console.log(
|
|
12939
12856
|
"\u2705 Registered components:",
|
|
12940
12857
|
generator.getComponentNames().join(", ")
|
|
@@ -12982,10 +12899,7 @@ async function runPluginDemo() {
|
|
|
12982
12899
|
await fs3.writeFile(outputPath, new Uint8Array(result.buffer));
|
|
12983
12900
|
console.log(`\u2705 Document saved to: ${outputPath}`);
|
|
12984
12901
|
const schemaPath = path2.join(outputDir, "plugin-demo-schema.json");
|
|
12985
|
-
await exportPluginSchema(
|
|
12986
|
-
[weatherComponent, columnsLayoutComponent, nestedSectionsComponent],
|
|
12987
|
-
schemaPath
|
|
12988
|
-
);
|
|
12902
|
+
await exportPluginSchema([weatherComponent], schemaPath);
|
|
12989
12903
|
console.log(`\u2705 Schema saved to: ${schemaPath}`);
|
|
12990
12904
|
} catch (error) {
|
|
12991
12905
|
console.error("\u274C Error generating document:", error);
|