@stonecrop/stonecrop 0.13.14 → 0.15.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.
Files changed (95) hide show
  1. package/README.md +6 -3
  2. package/dist/src/doctype.d.ts +42 -7
  3. package/dist/src/doctype.d.ts.map +1 -1
  4. package/dist/src/doctype.js +77 -18
  5. package/dist/src/index.d.ts +5 -1
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/index.js +6 -0
  8. package/dist/src/registry.d.ts +1 -1
  9. package/dist/src/registry.d.ts.map +1 -1
  10. package/dist/src/registry.js +46 -38
  11. package/dist/src/schema-validator.d.ts.map +1 -1
  12. package/dist/src/schema-validator.js +44 -47
  13. package/dist/src/stonecrop.d.ts +0 -6
  14. package/dist/src/stonecrop.d.ts.map +1 -1
  15. package/dist/src/stores/index.d.ts +2 -0
  16. package/dist/src/stores/index.d.ts.map +1 -1
  17. package/dist/src/stores/index.js +1 -0
  18. package/dist/src/stores/operation-log.d.ts +0 -6
  19. package/dist/src/stores/operation-log.d.ts.map +1 -1
  20. package/dist/src/stores/operation-log.js +0 -1
  21. package/dist/src/stores/validation.d.ts +83 -0
  22. package/dist/src/stores/validation.d.ts.map +1 -0
  23. package/dist/src/stores/validation.js +104 -0
  24. package/dist/src/types/doctype.d.ts +1 -1
  25. package/dist/src/types/doctype.d.ts.map +1 -1
  26. package/dist/src/types/operation-log.d.ts +0 -2
  27. package/dist/src/types/operation-log.d.ts.map +1 -1
  28. package/dist/stonecrop.d.ts +166 -22
  29. package/dist/stonecrop.js +5235 -1950
  30. package/dist/stonecrop.js.map +1 -1
  31. package/package.json +23 -23
  32. package/src/client-handler.ts +55 -0
  33. package/src/doctype.ts +83 -22
  34. package/src/index.ts +12 -0
  35. package/src/registry.ts +45 -40
  36. package/src/schema-validator.ts +52 -48
  37. package/src/stores/index.ts +2 -0
  38. package/src/stores/operation-log.ts +0 -1
  39. package/src/stores/validation.ts +138 -0
  40. package/src/types/doctype.ts +1 -1
  41. package/src/types/operation-log.ts +0 -3
  42. package/dist/composable.js +0 -1
  43. package/dist/composables/lazy-link.js +0 -125
  44. package/dist/composables/operation-log.js +0 -224
  45. package/dist/composables/stonecrop.js +0 -504
  46. package/dist/composables/use-lazy-link-state.js +0 -125
  47. package/dist/composables/use-stonecrop.js +0 -476
  48. package/dist/doctype.js +0 -242
  49. package/dist/exceptions.js +0 -16
  50. package/dist/field-triggers.js +0 -575
  51. package/dist/index.js +0 -27
  52. package/dist/operation-log-DB-dGNT9.js +0 -593
  53. package/dist/operation-log-DB-dGNT9.js.map +0 -1
  54. package/dist/plugins/index.js +0 -99
  55. package/dist/registry.js +0 -423
  56. package/dist/schema-validator.js +0 -407
  57. package/dist/src/composable.d.ts +0 -11
  58. package/dist/src/composable.d.ts.map +0 -1
  59. package/dist/src/composable.js +0 -477
  60. package/dist/src/composables/use-lazy-link-state.d.ts +0 -25
  61. package/dist/src/composables/use-lazy-link-state.d.ts.map +0 -1
  62. package/dist/src/composables/use-stonecrop.d.ts +0 -93
  63. package/dist/src/composables/use-stonecrop.d.ts.map +0 -1
  64. package/dist/src/composables/useNestedSchema.d.ts +0 -110
  65. package/dist/src/composables/useNestedSchema.d.ts.map +0 -1
  66. package/dist/src/composables/useNestedSchema.js +0 -155
  67. package/dist/src/stores/data.d.ts +0 -11
  68. package/dist/src/stores/data.d.ts.map +0 -1
  69. package/dist/src/stores/xstate.d.ts +0 -31
  70. package/dist/src/stores/xstate.d.ts.map +0 -1
  71. package/dist/src/tsdoc-metadata.json +0 -11
  72. package/dist/src/utils.d.ts +0 -24
  73. package/dist/src/utils.d.ts.map +0 -1
  74. package/dist/stonecrop.css +0 -1
  75. package/dist/stonecrop.umd.cjs +0 -6
  76. package/dist/stonecrop.umd.cjs.map +0 -1
  77. package/dist/stores/data.js +0 -7
  78. package/dist/stores/hst.js +0 -496
  79. package/dist/stores/index.js +0 -12
  80. package/dist/stores/operation-log.js +0 -580
  81. package/dist/stores/xstate.js +0 -29
  82. package/dist/tests/setup.d.ts +0 -5
  83. package/dist/tests/setup.d.ts.map +0 -1
  84. package/dist/tests/setup.js +0 -15
  85. package/dist/types/composable.js +0 -0
  86. package/dist/types/doctype.js +0 -0
  87. package/dist/types/field-triggers.js +0 -4
  88. package/dist/types/hst.js +0 -0
  89. package/dist/types/index.js +0 -10
  90. package/dist/types/operation-log.js +0 -0
  91. package/dist/types/plugin.js +0 -0
  92. package/dist/types/registry.js +0 -0
  93. package/dist/types/schema-validator.js +0 -13
  94. package/dist/types/stonecrop.js +0 -0
  95. package/dist/utils.js +0 -46
package/README.md CHANGED
@@ -26,6 +26,9 @@ const app = createApp(App)
26
26
  app.use(Stonecrop, {
27
27
  router,
28
28
 
29
+ // Run `onRouterInitialized` once the router is ready (defaults to false).
30
+ autoInitializeRouter: true,
31
+
29
32
  // Lazy-load doctype metadata from your API given the current route context.
30
33
  // routeContext = { path, segments } — adapt segments to your doctype naming.
31
34
  getMeta: async ({ segments }) => {
@@ -128,7 +131,7 @@ export default {
128
131
 
129
132
  // HST mode with lazy-loading — pass string doctype slug
130
133
  // Automatically loads doctype via registry.getMeta if not in registry
131
- const { isLoading, error, resolvedDoctype, formData } = useStonecrop({
134
+ const { isLoading, error, resolvedDoctype, resolvedSchema, formData } = useStonecrop({
132
135
  doctype: 'plan',
133
136
  recordId: 'record-123',
134
137
  })
@@ -153,7 +156,7 @@ When you pass a string doctype slug instead of a `Doctype` instance, `useStonecr
153
156
  3. Return `isLoading`, `error`, and `resolvedDoctype` refs for handling the async state
154
157
 
155
158
  ```typescript
156
- const { isLoading, error, resolvedDoctype, formData } = useStonecrop({
159
+ const { isLoading, error, resolvedDoctype, resolvedSchema, formData } = useStonecrop({
157
160
  doctype: 'plan', // string slug - triggers lazy-loading
158
161
  recordId: '123',
159
162
  })
@@ -161,7 +164,7 @@ const { isLoading, error, resolvedDoctype, formData } = useStonecrop({
161
164
  // In your template:
162
165
  // <div v-if="isLoading">Loading doctype...</div>
163
166
  // <div v-else-if="error">Error: {{ error.message }}</div>
164
- // <AForm v-else :schema="resolvedDoctype.schema" v-model:data="formData" />
167
+ // <AForm v-else :schema="resolvedSchema" v-model:data="formData" />
165
168
  ```
166
169
 
167
170
  This pattern eliminates the timing mismatch when loading doctypes asynchronously in Nuxt plugins.
@@ -1,4 +1,4 @@
1
- import type { DoctypeField, LinkDeclaration } from '@stonecrop/schema';
1
+ import type { DoctypeField, LinkDeclaration, TriggerDefinition } from '@stonecrop/schema';
2
2
  import { Component } from 'vue';
3
3
  import type { DoctypeConfig, ImmutableDoctype } from './types/doctype';
4
4
  /**
@@ -83,8 +83,8 @@ export default class Doctype {
83
83
  * const planDoctype = Doctype.fromObject({
84
84
  * name: 'Plan',
85
85
  * fields: [
86
- * { fieldname: 'title', label: 'Title', fieldtype: 'Data' },
87
- * { fieldname: 'status', label: 'Status', fieldtype: 'Data' },
86
+ * { fieldname: 'title', label: 'Title', component: 'ATextInput' },
87
+ * { fieldname: 'status', label: 'Status', component: 'ATextInput' },
88
88
  * ],
89
89
  * workflow: {
90
90
  * id: 'plan',
@@ -141,6 +141,44 @@ export default class Doctype {
141
141
  name: string;
142
142
  targetState: string;
143
143
  }>;
144
+ /**
145
+ * Returns the stateless **Commands** available in a given workflow state — side-effect
146
+ * actions (save/print/email…) that do not change workflow state. Unlike transitions,
147
+ * Commands may exist on a workflow that declares no `states` (a commands-only doctype),
148
+ * and a Command with no `allowedStates` is available in every state.
149
+ *
150
+ * Only meaningful for WorkflowMeta format; XState workflows have no Commands.
151
+ *
152
+ * @param currentState - The record's current state, used to honor a Command's `allowedStates`
153
+ * @returns Array of command descriptors with `name`
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const commands = doctype.getAvailableCommands('Draft')
158
+ * // [{ name: 'Print' }]
159
+ * ```
160
+ *
161
+ * @public
162
+ */
163
+ getAvailableCommands(currentState?: string): Array<{
164
+ name: string;
165
+ }>;
166
+ /**
167
+ * Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
168
+ * client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
169
+ * XState machine (no triggers), or simply declares none.
170
+ *
171
+ * @returns The `workflow.triggers` map, or undefined
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * const triggers = doctype.getTriggers()
176
+ * // { dateOrder: { on: ['start_date', 'end_date'], clientHandler: '…' } }
177
+ * ```
178
+ *
179
+ * @public
180
+ */
181
+ getTriggers(): Record<string, TriggerDefinition> | undefined;
144
182
  /**
145
183
  * Returns metadata for a specific action, if available.
146
184
  * Only works with WorkflowMeta format; returns undefined for XState format.
@@ -151,18 +189,15 @@ export default class Doctype {
151
189
  * @example
152
190
  * ```ts
153
191
  * const actionMeta = doctype.getActionMeta('submit')
154
- * // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
192
+ * // { label: 'Submit', allowedStates: ['draft'] }
155
193
  * ```
156
194
  *
157
195
  * @public
158
196
  */
159
197
  getActionMeta(actionName: string): {
160
198
  label: string;
161
- handler: string;
162
199
  requiredFields?: string[];
163
200
  allowedStates?: string[];
164
- confirm?: boolean;
165
- args?: Record<string, unknown>;
166
201
  } | undefined;
167
202
  /**
168
203
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
@@ -1 +1 @@
1
- {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAgB,MAAM,mBAAmB,CAAA;AAEpF,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEtE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,QAAQ,CAAC,MAAM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AS,CAAC,EAAE,SAAS,EACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAUxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAajD;;;;;;;;;;;;;;OAcG;IACH,cAAc,IAAI,YAAY,EAAE;IAKhC;;;;;;;OAOG;IACH,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAK5C;;;;;;;;;;;;;;OAcG;IACH,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAqC3F;;;;;;;;;;;;;;;;;;OAkBG;IACH,oBAAoB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAcpE;;;;;;;;;;;;;;OAcG;IACH,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SAAS;IAS5D;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAC7B;QACA,KAAK,EAAE,MAAM,CAAA;QACb,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;QACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;KACvB,GACD,SAAS;IAWZ;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,WAKP;CACD"}
@@ -1,3 +1,4 @@
1
+ import { isActionAllowedInState, normalizeFieldKind } from '@stonecrop/schema';
1
2
  import { List, Map } from 'immutable';
2
3
  /**
3
4
  * Doctype runtime class with Immutable.js collections for HST change tracking.
@@ -90,8 +91,8 @@ export default class Doctype {
90
91
  * const planDoctype = Doctype.fromObject({
91
92
  * name: 'Plan',
92
93
  * fields: [
93
- * { fieldname: 'title', label: 'Title', fieldtype: 'Data' },
94
- * { fieldname: 'status', label: 'Status', fieldtype: 'Data' },
94
+ * { fieldname: 'title', label: 'Title', component: 'ATextInput' },
95
+ * { fieldname: 'status', label: 'Status', component: 'ATextInput' },
95
96
  * ],
96
97
  * workflow: {
97
98
  * id: 'plan',
@@ -104,7 +105,13 @@ export default class Doctype {
104
105
  * @public
105
106
  */
106
107
  static fromObject(config) {
107
- const schema = config.fields ? List(config.fields) : List();
108
+ // Authored JSON may omit the `kind` discriminant; the Zod schema injects it via a
109
+ // preprocess, but this path bypasses Zod. Normalize here so the registry's
110
+ // `resolveFields` (which gates link/fieldset handling on `field.kind`) sees the same
111
+ // shape a parsed doctype would — otherwise links silently fail to expand.
112
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- normalizeFieldKind only injects the `kind` discriminant; the field shape is otherwise preserved
113
+ const fields = config.fields?.map(normalizeFieldKind);
114
+ const schema = fields ? List(fields) : List();
108
115
  const actions = config.actions ? Map(config.actions) : Map();
109
116
  return new Doctype(config.name, schema, config.workflow, actions, undefined, config.links);
110
117
  }
@@ -170,19 +177,14 @@ export default class Doctype {
170
177
  const actions = workflow.actions;
171
178
  if (!actions)
172
179
  return [];
173
- return Object.entries(actions)
174
- .filter(([, actionDef]) => {
175
- const allowedStates = actionDef.allowedStates;
176
- // If no allowedStates specified, action is available in all valid states
177
- if (!allowedStates || allowedStates.length === 0)
178
- return true;
179
- return allowedStates.includes(currentState);
180
- })
181
- .map(([name]) => ({
180
+ return (Object.entries(actions)
181
+ // Exclude stateless Commands — they change no state and are surfaced separately
182
+ // via getAvailableCommands(). Genuine transitions carry a nextState.
183
+ .filter(([, actionDef]) => !actionDef.stateless && isActionAllowedInState(actionDef, currentState))
184
+ .map(([name, actionDef]) => ({
182
185
  name,
183
- // WorkflowMeta doesn't define target states - transitions are handled server-side
184
- targetState: currentState,
185
- }));
186
+ targetState: actionDef.nextState ?? currentState,
187
+ })));
186
188
  }
187
189
  // XState format: use the on property of the state
188
190
  const states = workflow.states;
@@ -196,6 +198,61 @@ export default class Doctype {
196
198
  targetState: typeof target === 'string' ? target : 'unknown',
197
199
  }));
198
200
  }
201
+ /**
202
+ * Returns the stateless **Commands** available in a given workflow state — side-effect
203
+ * actions (save/print/email…) that do not change workflow state. Unlike transitions,
204
+ * Commands may exist on a workflow that declares no `states` (a commands-only doctype),
205
+ * and a Command with no `allowedStates` is available in every state.
206
+ *
207
+ * Only meaningful for WorkflowMeta format; XState workflows have no Commands.
208
+ *
209
+ * @param currentState - The record's current state, used to honor a Command's `allowedStates`
210
+ * @returns Array of command descriptors with `name`
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * const commands = doctype.getAvailableCommands('Draft')
215
+ * // [{ name: 'Print' }]
216
+ * ```
217
+ *
218
+ * @public
219
+ */
220
+ getAvailableCommands(currentState) {
221
+ const workflow = this.workflow;
222
+ if (!workflow)
223
+ return [];
224
+ // Only WorkflowMeta carries an `actions` map; XState workflows have no Commands.
225
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
226
+ const actions = workflow.actions;
227
+ if (!actions)
228
+ return [];
229
+ return Object.entries(actions)
230
+ .filter(([, actionDef]) => actionDef.stateless === true && isActionAllowedInState(actionDef, currentState ?? ''))
231
+ .map(([name]) => ({ name }));
232
+ }
233
+ /**
234
+ * Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
235
+ * client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
236
+ * XState machine (no triggers), or simply declares none.
237
+ *
238
+ * @returns The `workflow.triggers` map, or undefined
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * const triggers = doctype.getTriggers()
243
+ * // { dateOrder: { on: ['start_date', 'end_date'], clientHandler: '…' } }
244
+ * ```
245
+ *
246
+ * @public
247
+ */
248
+ getTriggers() {
249
+ const workflow = this.workflow;
250
+ if (!workflow)
251
+ return undefined;
252
+ // Only WorkflowMeta carries a `triggers` map; XState workflows have none.
253
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta triggers map
254
+ return workflow.triggers;
255
+ }
199
256
  /**
200
257
  * Returns metadata for a specific action, if available.
201
258
  * Only works with WorkflowMeta format; returns undefined for XState format.
@@ -206,16 +263,18 @@ export default class Doctype {
206
263
  * @example
207
264
  * ```ts
208
265
  * const actionMeta = doctype.getActionMeta('submit')
209
- * // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
266
+ * // { label: 'Submit', allowedStates: ['draft'] }
210
267
  * ```
211
268
  *
212
269
  * @public
213
270
  */
214
271
  getActionMeta(actionName) {
215
272
  const workflow = this.workflow;
216
- if (!workflow || !Array.isArray(workflow.states))
273
+ if (!workflow)
217
274
  return undefined;
218
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Array.isArray(workflow.states) confirms WorkflowMeta format above
275
+ // Only WorkflowMeta carries an `actions` map (with labels); XState workflows have none.
276
+ // Don't require a `states` array — a commands-only doctype has labeled actions but no states.
277
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
219
278
  const actions = workflow.actions;
220
279
  return actions?.[actionName];
221
280
  }
@@ -1,5 +1,6 @@
1
1
  export type * from '@stonecrop/aform/types';
2
2
  export type * from '@stonecrop/atable/types';
3
+ import { executeClientHandler } from './client-handler';
3
4
  import { useLazyLink } from './composables/lazy-link';
4
5
  import { useStonecrop } from './composables/stonecrop';
5
6
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
@@ -10,10 +11,13 @@ import Registry from './registry';
10
11
  import { Stonecrop, getStonecrop } from './stonecrop';
11
12
  import { HST, createHST, type HSTNode } from './stores/hst';
12
13
  import { useOperationLogStore } from './stores/operation-log';
14
+ import { useValidationStore } from './stores/validation';
13
15
  import { SchemaValidator, createValidator, validateSchema } from './schema-validator';
14
16
  import { ValidationSeverity } from './types/schema-validator';
15
17
  export type * from './types';
18
+ export type { ClientHandlerApi } from './client-handler';
19
+ export type { ValidationError } from './stores/validation';
16
20
  export { ValidationSeverity };
17
- export { Doctype, Registry, Stonecrop, useLazyLink, useStonecrop, HST, createHST, HSTNode, FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, getStonecrop, };
21
+ export { Doctype, Registry, Stonecrop, useLazyLink, useStonecrop, executeClientHandler, HST, createHST, HSTNode, FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, useValidationStore, getStonecrop, };
18
22
  export default plugin;
19
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,wBAAwB,CAAA;AAC3C,mBAAmB,yBAAyB,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC9F,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,OAAO,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AO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAG7D,mBAAmB,SAAS,CAAA;AAG5B,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAG1D,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,OAAO,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,WAAW,EACX,YAAY,EAEZ,oBAAoB,EAEpB,GAAG,EACH,SAAS,EACT,OAAO,EAEP,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EAEzB,eAAe,EACf,eAAe,EACf,cAAc,EAEd,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EAET,kBAAkB,EAElB,YAAY,GACZ,CAAA;AAGD,eAAe,MAAM,CAAA"}
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { executeClientHandler } from './client-handler';
1
2
  import { useLazyLink } from './composables/lazy-link';
2
3
  import { useStonecrop } from './composables/stonecrop';
3
4
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
@@ -8,11 +9,14 @@ import Registry from './registry';
8
9
  import { Stonecrop, getStonecrop } from './stonecrop';
9
10
  import { HST, createHST } from './stores/hst';
10
11
  import { useOperationLogStore } from './stores/operation-log';
12
+ import { useValidationStore } from './stores/validation';
11
13
  import { SchemaValidator, createValidator, validateSchema } from './schema-validator';
12
14
  import { ValidationSeverity } from './types/schema-validator';
13
15
  // Export enum as value (enums need runtime export, not just type)
14
16
  export { ValidationSeverity };
15
17
  export { Doctype, Registry, Stonecrop, useLazyLink, useStonecrop,
18
+ // clientHandler executor
19
+ executeClientHandler,
16
20
  // HST exports for advanced usage
17
21
  HST, createHST,
18
22
  // Field trigger system exports
@@ -21,6 +25,8 @@ FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransi
21
25
  SchemaValidator, createValidator, validateSchema,
22
26
  // Operation log exports
23
27
  useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch,
28
+ // Field-validation store
29
+ useValidationStore,
24
30
  // Utility functions
25
31
  getStonecrop, };
26
32
  // Default export is the Vue plugin
@@ -102,7 +102,7 @@ export default class Registry {
102
102
  *
103
103
  * - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
104
104
  * - `kind: 'fieldset'` → recursively initializes children as `{}`
105
- * - `kind: 'field'` → derives default from `fieldtype`; falls back to `null`
105
+ * - `kind: 'field'` → derives the default from the component's category; falls back to `null`
106
106
  *
107
107
  * @param schema - The resolved schema array to derive defaults from
108
108
  * @returns A plain object with default values for each field
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAiE,MAAM,kBAAkB,CAAA;AACpH,OAAO,KAAK,EAA8B,eAAe,EAA+B,MAAM,mBAAmB,CAAA;AACjH,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAA;IAEtB;;;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,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,aAAa,EAAE;IA4BvE;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA2FrB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAuC9D;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI7C;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAWvF;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBtG;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAgC5B"}
@@ -1,3 +1,4 @@
1
+ import { componentCategory, componentLinkExpansion, resolveLinkRenderMode } from '@stonecrop/schema';
1
2
  import { getGlobalTriggerEngine } from './field-triggers';
2
3
  /**
3
4
  * Stonecrop Registry class
@@ -137,21 +138,21 @@ export default class Registry {
137
138
  resolveFields(fields, links, visited) {
138
139
  const resolved = [];
139
140
  for (const field of fields) {
140
- if (field.kind === 'field' && field.fieldtype === 'Link') {
141
- const link = links.get(field.fieldname);
142
- if (!link) {
143
- // Unresolved link — warn and produce a scalar with component: 'AFormLink'
144
- const linkDoctype = typeof field.options === 'string' ? field.options : undefined;
145
- if (linkDoctype === undefined) {
146
- console.warn(`[Stonecrop] Link field "${field.fieldname}" has no \`options\` or corresponding \`links\` declaration. ` +
147
- `AFormLink will be created without a \`doctype\` prop, so navigation will not work. ` +
148
- `Add \`"options": "<doctype-slug>"\` to the field definition.`);
149
- }
141
+ // A field is a link when it carries `doctype` (the marker) or has a LinkDeclaration.
142
+ const linkDecl = field.kind === 'field' ? links.get(field.fieldname) : undefined;
143
+ if (field.kind === 'field' && (linkDecl || field.doctype)) {
144
+ const link = linkDecl;
145
+ // The declaration's target wins over the field's own `doctype`.
146
+ const linkTarget = link?.target ?? field.doctype;
147
+ // An undeclared link, or a declared one whose component renders an inline picker,
148
+ // stays a scalar: the target is not expanded, it only needs the slug for async
149
+ // display-text resolution and navigation.
150
+ if (!link || resolveLinkRenderMode(link, field.component) === 'inline') {
150
151
  const { cardinality: _c, ...rest } = field;
151
152
  resolved.push({
152
153
  ...rest,
153
154
  component: rest.component || 'AFormLink',
154
- ...(linkDoctype !== undefined ? { doctype: linkDoctype } : {}),
155
+ ...(linkTarget !== undefined ? { doctype: linkTarget } : {}),
155
156
  });
156
157
  continue;
157
158
  }
@@ -163,8 +164,8 @@ export default class Registry {
163
164
  continue;
164
165
  }
165
166
  const childSchema = this.resolveSchema(targetDoctype, new Set(visited));
166
- const { fieldtype: _ft, options: _opt, cardinality: _card, kind: _kind, ...fieldRest } = field;
167
- if (link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne') {
167
+ const { options: _opt, cardinality: _card, kind: _kind, ...fieldRest } = field;
168
+ if (resolveLinkRenderMode(link, field.component) === 'table') {
168
169
  resolved.push(this.buildTableConfig(field, childSchema, link.component));
169
170
  }
170
171
  else {
@@ -200,7 +201,16 @@ export default class Registry {
200
201
  resolved.push(tableEntry);
201
202
  }
202
203
  else {
203
- // Scalar field (kind: 'field', not a Link) — strip cardinality
204
+ // Scalar field (kind: 'field', not a link) — strip cardinality.
205
+ // A link-rendering component with nothing to point at renders an empty picker (or an
206
+ // empty embedded form), which is indistinguishable from "the record has no value".
207
+ // Link-ness comes from `doctype`/`links`, so this is a field that named a link
208
+ // component and forgot the target.
209
+ if (field.kind === 'field' && componentLinkExpansion(field.component)) {
210
+ console.warn(`[Stonecrop] Field "${field.fieldname}" renders with "${field.component}", which is a link component, ` +
211
+ `but the field is not a link: it has no \`doctype\` and no \`links\` declaration. It will render ` +
212
+ `as a plain field. Add \`"doctype": "<doctype-slug>"\` to the field definition.`);
213
+ }
204
214
  const { cardinality: _c, ...rest } = field;
205
215
  resolved.push({ ...rest });
206
216
  }
@@ -218,7 +228,7 @@ export default class Registry {
218
228
  .filter((f) => f.kind === 'field')
219
229
  .map(({ kind: _k, ...col }) => col);
220
230
  const config = field.config ?? { view: 'list' };
221
- const { fieldtype: _ft, options: _opt, cardinality: _card, ...fieldRest } = field;
231
+ const { options: _opt, cardinality: _card, ...fieldRest } = field;
222
232
  return {
223
233
  ...fieldRest,
224
234
  kind: 'table',
@@ -234,7 +244,7 @@ export default class Registry {
234
244
  *
235
245
  * - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
236
246
  * - `kind: 'fieldset'` → recursively initializes children as `{}`
237
- * - `kind: 'field'` → derives default from `fieldtype`; falls back to `null`
247
+ * - `kind: 'field'` → derives the default from the component's category; falls back to `null`
238
248
  *
239
249
  * @param schema - The resolved schema array to derive defaults from
240
250
  * @returns A plain object with default values for each field
@@ -253,33 +263,31 @@ export default class Registry {
253
263
  record[field.fieldname] = this.initializeRecord(field.schema);
254
264
  }
255
265
  else {
256
- // kind: 'field' — derive from fieldtype
266
+ // kind: 'field' — the empty default comes from the component's category.
257
267
  const fieldDefault = field.default;
258
268
  if (fieldDefault !== undefined) {
259
269
  record[field.fieldname] = fieldDefault;
260
270
  }
261
271
  else {
262
- switch (field.fieldtype) {
263
- case 'Data':
264
- case 'Text':
265
- case 'Code':
266
- record[field.fieldname] = '';
267
- break;
268
- case 'Check':
269
- record[field.fieldname] = false;
270
- break;
271
- case 'Int':
272
- case 'Float':
273
- case 'Decimal':
274
- case 'Currency':
275
- case 'Quantity':
276
- record[field.fieldname] = 0;
277
- break;
278
- case 'JSON':
279
- record[field.fieldname] = {};
280
- break;
281
- default:
282
- record[field.fieldname] = null;
272
+ const category = componentCategory(field.component);
273
+ if (category === 'text') {
274
+ record[field.fieldname] = '';
275
+ }
276
+ else if (category === 'number') {
277
+ record[field.fieldname] = 0;
278
+ }
279
+ else if (category === 'boolean') {
280
+ record[field.fieldname] = false;
281
+ }
282
+ else if (category === 'code' && field.language) {
283
+ // A JSON editor starts from an empty object; any other language from empty source.
284
+ record[field.fieldname] = field.language === 'json' ? {} : '';
285
+ }
286
+ else {
287
+ // date / datetime / select / link / attach — plus two cases with no better answer
288
+ // than "no value": an unknown (custom) component, and a code field whose missing
289
+ // `language` doesn't say which kind of empty it wants.
290
+ record[field.fieldname] = null;
283
291
  }
284
292
  }
285
293
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/schema-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAGhD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAEtC,OAAO,KAAK,EAAmB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEnG;;;GAGG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,OAAO,CAA4B;IAE3C;;;OAGG;gBACS,OAAO,GAAE,gBAAqB;IAW1C;;;;;;;;OAQG;IACH,QAAQ,CACP,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,YAAY,EAAE,GAAG,SAAS,EACvD,QAAQ,CAAC,EAAE,kBAAkB,EAC7B,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,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