@nodish/core 0.1.2 → 0.1.4

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Register built-in Vue widgets for the core `number` and `string` types.
2
+ * Register built-in Vue widgets for conventional `number` and `string` type ids.
3
3
  * Call once at app startup before loading packs that rely on those widgets.
4
4
  */
5
5
  export declare function registerDefaultTypeWidgets(): void;
@@ -7,10 +7,8 @@ export interface CreateNodeMapInit {
7
7
  graph?: NodeGraph;
8
8
  /** Pre-loaded pack ids (usually leave empty and use {@link NodeMap.loadPack}). */
9
9
  extensions?: string[];
10
- /** Graph boundary ports; defaults to `a`/`b` in, `result` out. */
10
+ /** Graph boundary ports; defaults to no inputs and no outputs. */
11
11
  graphInterface?: GraphInterface;
12
- /** Register the built-in `@local/core` pack. Default: `true`. */
13
- defaultPack?: boolean;
14
12
  /** Extra types to merge into the registry at creation time. */
15
13
  types?: TypeRegistry;
16
14
  /** Extra node types to merge into the registry at creation time (authoring form). */
@@ -5,7 +5,7 @@ export type { CreateNodeMapInit, GraphDocument };
5
5
  * Create an in-memory graph workspace with registries, boundary nodes, and
6
6
  * {@link NodeMap.loadPack} wired for widget setup.
7
7
  *
8
- * Loads the built-in core pack by default unless `defaultPack: false`.
9
- * Registers built-in number/string widgets on first call.
8
+ * Registers built-in `number`/`string` widgets on first call (for packs that
9
+ * use those conventional type ids).
10
10
  */
11
11
  export declare function createNodeMap(init?: CreateNodeMapInit): import('.').NodeMap;
package/dist/vue.js CHANGED
@@ -63,17 +63,8 @@ function j(e) {
63
63
  //#endregion
64
64
  //#region src/store/model.ts
65
65
  var M = {
66
- parameters: {
67
- a: {
68
- type: "number",
69
- defaultValue: 0
70
- },
71
- b: {
72
- type: "number",
73
- defaultValue: 0
74
- }
75
- },
76
- returns: { result: { type: "number" } }
66
+ parameters: {},
67
+ returns: {}
77
68
  };
78
69
  //#endregion
79
70
  //#region src/store/registry/defineNode.ts
@@ -2247,139 +2238,8 @@ function In() {
2247
2238
  Je("number", Q), Je("string", $);
2248
2239
  }
2249
2240
  //#endregion
2250
- //#region src/store/nodes/math.ts
2251
- var Ln = {
2252
- typeId: "math/add",
2253
- displayName: "Add",
2254
- color: "#4a7a4a",
2255
- description: "Add two numbers",
2256
- group: ["math", "basic operations"],
2257
- inputs: {
2258
- a: {
2259
- type: "number",
2260
- defaultValue: 0
2261
- },
2262
- b: {
2263
- type: "number",
2264
- defaultValue: 0
2265
- }
2266
- },
2267
- outputs: { sum: { type: "number" } },
2268
- execute: (e) => ({ sum: Number(e.a ?? 0) + Number(e.b ?? 0) })
2269
- }, Rn = {
2270
- typeId: "math/multiply",
2271
- displayName: "Multiply",
2272
- color: "#4a7a4a",
2273
- description: "Multiply two numbers",
2274
- group: ["math", "basic operations"],
2275
- inputs: {
2276
- a: {
2277
- type: "number",
2278
- defaultValue: 0
2279
- },
2280
- b: {
2281
- type: "number",
2282
- defaultValue: 0
2283
- }
2284
- },
2285
- outputs: { product: { type: "number" } },
2286
- execute: (e) => ({ product: Number(e.a ?? 0) * Number(e.b ?? 0) })
2287
- }, zn = {
2288
- typeId: "math/divide",
2289
- displayName: "Divide",
2290
- color: "#4a7a4a",
2291
- description: "Divide two numbers",
2292
- group: ["math", "basic operations"],
2293
- inputs: {
2294
- a: {
2295
- type: "number",
2296
- defaultValue: 0
2297
- },
2298
- b: {
2299
- type: "number",
2300
- defaultValue: 1
2301
- }
2302
- },
2303
- outputs: { quotient: { type: "number" } },
2304
- execute: (e) => {
2305
- let t = Number(e.a ?? 0), n = Number(e.b ?? 1);
2306
- if (n === 0) throw Error("Division by zero");
2307
- return { quotient: t / n };
2308
- }
2309
- }, Bn = {
2310
- [Ln.typeId]: Ln,
2311
- [Rn.typeId]: Rn,
2312
- [zn.typeId]: zn
2313
- };
2314
- //#endregion
2315
- //#region src/store/registry/defineType.ts
2316
- function Vn(e) {
2317
- let t = e.widget, n = Wn(t);
2318
- return {
2319
- id: e.id,
2320
- label: e.label ?? Hn(e.id),
2321
- color: e.color ?? "#888",
2322
- validate: e.validate,
2323
- accepts: e.accepts,
2324
- defaultValue: e.defaultValue,
2325
- widget: t,
2326
- parse: e.parse ?? n.parse,
2327
- format: e.format ?? n.format,
2328
- coerce: e.coerce ?? n.coerce
2329
- };
2330
- }
2331
- function Hn(e) {
2332
- return e.charAt(0).toUpperCase() + e.slice(1);
2333
- }
2334
- function Un(e, t, n) {
2335
- let r = Number(e);
2336
- return Number.isNaN(r) && (r = 0), t !== void 0 && (r = Math.max(t, r)), n !== void 0 && (r = Math.min(n, r)), r;
2337
- }
2338
- function Wn(e) {
2339
- if (!e) return {
2340
- parse: (e) => e,
2341
- format: (e) => e == null ? "" : String(e)
2342
- };
2343
- switch (e.kind) {
2344
- case "number": return {
2345
- parse: (e) => Number(e),
2346
- format: (e) => e == null ? "" : String(e),
2347
- coerce: (t) => Un(t, e.min, e.max)
2348
- };
2349
- case "text": return {
2350
- parse: (e) => e,
2351
- format: (e) => e == null ? "" : String(e)
2352
- };
2353
- case "custom": return { format: (e) => e == null ? "" : String(e) };
2354
- }
2355
- }
2356
- //#endregion
2357
- //#region src/store/types/index.ts
2358
- var Gn = Vn({
2359
- id: "number",
2360
- label: "Number",
2361
- color: "#7dd3fc",
2362
- validate: (e) => typeof e == "number" && !Number.isNaN(e),
2363
- defaultValue: 0,
2364
- widget: { kind: "number" }
2365
- }), Kn = Vn({
2366
- id: "string",
2367
- label: "String",
2368
- color: "#c4b5fd",
2369
- validate: (e) => typeof e == "string",
2370
- defaultValue: "",
2371
- widget: { kind: "text" }
2372
- }), qn = {
2373
- id: "@local/core",
2374
- types: {
2375
- [Gn.id]: Gn,
2376
- [Kn.id]: Kn
2377
- },
2378
- nodeTypes: Bn
2379
- };
2380
- //#endregion
2381
2241
  //#region src/store/graph/createNodeMap.ts
2382
- function Jn(e = {}) {
2242
+ function Ln(e = {}) {
2383
2243
  let t = {
2384
2244
  graph: e.graph ?? {
2385
2245
  nodes: [],
@@ -2395,7 +2255,7 @@ function Jn(e = {}) {
2395
2255
  }
2396
2256
  //#endregion
2397
2257
  //#region src/store/packs/installPack.ts
2398
- function Yn(e, t, n) {
2258
+ function Rn(e, t, n) {
2399
2259
  if (e.extensions.includes(t.id)) return [];
2400
2260
  let r = [];
2401
2261
  if (t.types) for (let n of Object.keys(t.types)) e.types[n] && r.push(`type "${n}" already registered by another pack`);
@@ -2404,53 +2264,53 @@ function Yn(e, t, n) {
2404
2264
  }
2405
2265
  //#endregion
2406
2266
  //#region src/vue/attachLoadPack.ts
2407
- function Xn() {
2267
+ function zn() {
2408
2268
  return {
2409
2269
  registerTypeWidget: Je,
2410
2270
  registerComponentWidget: Ye
2411
2271
  };
2412
2272
  }
2413
- function Zn(e) {
2414
- e.loadPack = (t) => Yn(e, t, Xn());
2273
+ function Bn(e) {
2274
+ e.loadPack = (t) => Rn(e, t, zn());
2415
2275
  }
2416
2276
  //#endregion
2417
2277
  //#region src/vue/createNodeMap.ts
2418
- var Qn = !1;
2419
- function $n(e = {}) {
2420
- Qn ||= (In(), !0);
2421
- let t = Jn(e);
2422
- Zn(t), e.defaultPack !== !1 && t.loadPack(qn);
2278
+ var Vn = !1;
2279
+ function Hn(e = {}) {
2280
+ Vn ||= (In(), !0);
2281
+ let t = Ln(e);
2282
+ Bn(t);
2423
2283
  for (let n of e.packs ?? []) t.loadPack(n);
2424
2284
  return t;
2425
2285
  }
2426
2286
  //#endregion
2427
2287
  //#region src/store/graph/validateGraphTypes.ts
2428
- function er(e, t, n, r, i) {
2288
+ function Un(e, t, n, r, i) {
2429
2289
  e.types[n.type] || i.push(`node "${t.label ?? t.typeId}" (${t.id}): unknown ${r} port type "${n.type}" on port "${n.name}"`);
2430
2290
  }
2431
- function tr(e, t, n) {
2291
+ function Wn(e, t, n) {
2432
2292
  e.nodeTypes[t.typeId] || n.push(`node "${t.label ?? t.id}": unknown typeId "${t.typeId}"`);
2433
- for (let r of Object.values(t.inputs)) er(e, t, r, "input", n);
2434
- for (let r of Object.values(t.outputs)) er(e, t, r, "output", n);
2435
- t.composite?.graph && nr(e, t.composite.graph, n);
2293
+ for (let r of Object.values(t.inputs)) Un(e, t, r, "input", n);
2294
+ for (let r of Object.values(t.outputs)) Un(e, t, r, "output", n);
2295
+ t.composite?.graph && Gn(e, t.composite.graph, n);
2436
2296
  }
2437
- function nr(e, t, n = []) {
2438
- for (let r of t.nodes) tr(e, r, n);
2297
+ function Gn(e, t, n = []) {
2298
+ for (let r of t.nodes) Wn(e, r, n);
2439
2299
  return n;
2440
2300
  }
2441
2301
  //#endregion
2442
2302
  //#region src/store/graph/document.ts
2443
- function rr(e) {
2303
+ function Kn(e) {
2444
2304
  return {
2445
2305
  graph: z(e.graph),
2446
2306
  interface: z(e.graphInterface),
2447
2307
  extensions: e.extensions.length ? [...e.extensions] : void 0
2448
2308
  };
2449
2309
  }
2450
- function ir(e) {
2451
- return rr(e);
2310
+ function qn(e) {
2311
+ return Kn(e);
2452
2312
  }
2453
- function ar(e) {
2313
+ function Jn(e) {
2454
2314
  let t;
2455
2315
  try {
2456
2316
  t = JSON.parse(e);
@@ -2466,22 +2326,64 @@ function ar(e) {
2466
2326
  if (n.extensions !== void 0 && (!Array.isArray(n.extensions) || n.extensions.some((e) => typeof e != "string"))) throw Error("extensions must be an array of strings");
2467
2327
  return n;
2468
2328
  }
2469
- function or(e, t) {
2329
+ function Yn(e, t) {
2470
2330
  return t?.length ? t.filter((t) => !e.extensions.includes(t)).map((e) => `missing pack "${e}" (call map.loadPack() before import)`) : [];
2471
2331
  }
2472
- function sr(e, t) {
2332
+ function Xn(e, t) {
2473
2333
  let n = [];
2474
- return n.push(...or(e, t.extensions)), n.push(...se({
2334
+ return n.push(...Yn(e, t.extensions)), n.push(...se({
2475
2335
  ...e,
2476
2336
  graph: t.graph
2477
- })), n.push(...B(e, t.interface)), n.push(...nr(e, t.graph)), n;
2337
+ })), n.push(...B(e, t.interface)), n.push(...Gn(e, t.graph)), n;
2478
2338
  }
2479
- function cr(e, t) {
2480
- let n = or(e, t.extensions);
2481
- return n.length ? n : (e.graph = z(t.graph), e.graphInterface = z(t.interface), ie(e, e.graphInterface), oe(e), n.push(...sr(e, t)), n);
2339
+ function Zn(e, t) {
2340
+ let n = Yn(e, t.extensions);
2341
+ return n.length ? n : (e.graph = z(t.graph), e.graphInterface = z(t.interface), ie(e, e.graphInterface), oe(e), n.push(...Xn(e, t)), n);
2482
2342
  }
2483
- function lr(e, t) {
2484
- return cr(e, t);
2343
+ function Qn(e, t) {
2344
+ return Zn(e, t);
2345
+ }
2346
+ //#endregion
2347
+ //#region src/store/registry/defineType.ts
2348
+ function $n(e) {
2349
+ let t = e.widget, n = nr(t);
2350
+ return {
2351
+ id: e.id,
2352
+ label: e.label ?? er(e.id),
2353
+ color: e.color ?? "#888",
2354
+ validate: e.validate,
2355
+ accepts: e.accepts,
2356
+ defaultValue: e.defaultValue,
2357
+ widget: t,
2358
+ parse: e.parse ?? n.parse,
2359
+ format: e.format ?? n.format,
2360
+ coerce: e.coerce ?? n.coerce
2361
+ };
2362
+ }
2363
+ function er(e) {
2364
+ return e.charAt(0).toUpperCase() + e.slice(1);
2365
+ }
2366
+ function tr(e, t, n) {
2367
+ let r = Number(e);
2368
+ return Number.isNaN(r) && (r = 0), t !== void 0 && (r = Math.max(t, r)), n !== void 0 && (r = Math.min(n, r)), r;
2369
+ }
2370
+ function nr(e) {
2371
+ if (!e) return {
2372
+ parse: (e) => e,
2373
+ format: (e) => e == null ? "" : String(e)
2374
+ };
2375
+ switch (e.kind) {
2376
+ case "number": return {
2377
+ parse: (e) => Number(e),
2378
+ format: (e) => e == null ? "" : String(e),
2379
+ coerce: (t) => tr(t, e.min, e.max)
2380
+ };
2381
+ case "text": return {
2382
+ parse: (e) => e,
2383
+ format: (e) => e == null ? "" : String(e)
2384
+ };
2385
+ case "custom": return { format: (e) => e == null ? "" : String(e) };
2386
+ }
2485
2387
  }
2486
2388
  //#endregion
2487
- export { V as INPUT_TYPE, Fn as NodeViewer, H as OUTPUT_TYPE, cr as applyDocument, ae as boundaryNodes, $n as createNodeMap, Vn as defineType, ir as exportGraph, lr as importGraph, R as instantiate, ar as parseGraphDocument, Ye as registerComponentWidget, In as registerDefaultTypeWidgets, Je as registerTypeWidget, he as runGraph, rr as serializeDocument, sr as validateDocument };
2389
+ export { V as INPUT_TYPE, Fn as NodeViewer, H as OUTPUT_TYPE, Zn as applyDocument, ae as boundaryNodes, Hn as createNodeMap, $n as defineType, qn as exportGraph, Qn as importGraph, R as instantiate, Jn as parseGraphDocument, Ye as registerComponentWidget, In as registerDefaultTypeWidgets, Je as registerTypeWidget, he as runGraph, Kn as serializeDocument, Xn as validateDocument };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nodish/core",
3
3
  "private": false,
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
7
  "**/*.css"
@@ -21,10 +21,11 @@
21
21
  }
22
22
  },
23
23
  "scripts": {
24
- "preinstall": "node scripts/copy-dev-to-local.mjs",
25
- "dev": "vite --config vite.config.dev.ts",
24
+ "setup:local": "node scripts/copy-dev-to-local.mjs",
25
+ "dev": "node scripts/copy-dev-to-local.mjs && vite --config vite.config.dev.ts",
26
26
  "build": "vite build --config vite.config.pack.ts && vite build --config vite.config.vue.ts && dts-bundle-generator --export-referenced-types --no-check -o dist/pack.d.ts src/pack/index.ts",
27
- "typecheck": "tsc --noEmit"
27
+ "typecheck": "tsc --noEmit",
28
+ "typecheck:dev": "tsc --noEmit -p tsconfig.dev.json"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "vue": "^3.5.0"
package/readme.md CHANGED
@@ -5,8 +5,9 @@ An extensible node editor.
5
5
  ## Development
6
6
 
7
7
  ```bash
8
- npm i # will make a copy of /dev to /local, which is in the .gitignore
9
- npm run dev # will start the development server
8
+ npm i
9
+ npm run setup:local # copies /dev /local (first time only; local/ is gitignored)
10
+ npm run dev
10
11
  ```
11
12
 
12
13
  ## Examples
@@ -1,2 +0,0 @@
1
- import { NodeSpecRegistry } from '../registry/defineNode';
2
- export declare const defaultNodes: NodeSpecRegistry;
@@ -1,4 +0,0 @@
1
- import { NodeSpec } from '../registry/defineNode';
2
- export declare const addNode: NodeSpec;
3
- export declare const multiplyNode: NodeSpec;
4
- export declare const divideNode: NodeSpec;
@@ -1,3 +0,0 @@
1
- import { NodePack } from '../registry';
2
- export declare const CORE_PACK_ID = "@local/core";
3
- export declare const corePack: NodePack;
@@ -1,4 +0,0 @@
1
- import { TypeRegistry } from '../model';
2
- export declare const numberType: import('../model').PortTypeDefinition;
3
- export declare const stringType: import('../model').PortTypeDefinition;
4
- export declare const defaultTypes: TypeRegistry;