@seamware/odrl-policy-editor 1.7.3 → 1.8.0-PRE-66.42
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 +56 -2
- package/dist-component/odrl-policy-editor.d.ts +30 -8
- package/dist-component/odrl-policy-editor.js +6297 -6272
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -331,6 +331,7 @@ at runtime triggers a re-render automatically.
|
|
|
331
331
|
| `locale` | Language code (e.g., `"en"`, `"de"`) | `"en"` |
|
|
332
332
|
| `policy-context`| Default `@context` for new policies (JSON string) | `{"odrl":"http://www.w3.org/ns/odrl/2/"}` |
|
|
333
333
|
| `service-id` | Service ID for service-scoped policy/template operations | `null` |
|
|
334
|
+
| `persist` | Boolean — set to `"false"` to emit policies instead of storing them | `true` (stores) |
|
|
334
335
|
| `hide-builder-tab` | Boolean — hides the visual policy builder tab | absent (visible) |
|
|
335
336
|
| `hide-raw-tab` | Boolean — hides the raw ODRL JSON editor tab | absent (visible) |
|
|
336
337
|
| `hide-template-tab` | Boolean — hides the template selection tab | absent (visible) |
|
|
@@ -413,8 +414,8 @@ Events bubble and cross Shadow DOM boundaries (`composed: true`).
|
|
|
413
414
|
|
|
414
415
|
| Event | Detail payload | Fired when |
|
|
415
416
|
|--------------------|---------------------------------------------|----------------------------------|
|
|
416
|
-
| `policy-created` | `{ policy: OdrlPolicyJson, id: string }`
|
|
417
|
-
| `policy-updated` | `{ policy: OdrlPolicyJson, id: string }`
|
|
417
|
+
| `policy-created` | `{ policy: OdrlPolicyJson, id: string, persisted: boolean }` | A new policy is saved (or, with `persist="false"`, completed) |
|
|
418
|
+
| `policy-updated` | `{ policy: OdrlPolicyJson, id: string, persisted: boolean }` | An existing policy is updated |
|
|
418
419
|
| `policy-validated` | `{ result: ValidationResponse }` | Policy validation completes |
|
|
419
420
|
| `editor-cancelled` | `{}` | The user clicks Cancel |
|
|
420
421
|
| `template-created` | `{ template: object, id: string }` | A new template is created in the management tab |
|
|
@@ -439,6 +440,59 @@ editor.addEventListener('editor-cancelled', () => {
|
|
|
439
440
|
});
|
|
440
441
|
```
|
|
441
442
|
|
|
443
|
+
### Emit-Only Mode (`persist="false"`)
|
|
444
|
+
|
|
445
|
+
By default the editor stores a policy in the PAP and *then* emits
|
|
446
|
+
`policy-created` / `policy-updated`. Set `persist="false"` to turn the
|
|
447
|
+
component into a pure policy *builder*: the user configures the policy as
|
|
448
|
+
usual, but on Save nothing is written — the finished ODRL JSON is handed to
|
|
449
|
+
the host application through the very same events, with
|
|
450
|
+
`detail.persisted === false`.
|
|
451
|
+
|
|
452
|
+
```html
|
|
453
|
+
<odrl-policy-editor
|
|
454
|
+
id="editor"
|
|
455
|
+
api-base-url="https://pap.example.com"
|
|
456
|
+
persist="false"
|
|
457
|
+
></odrl-policy-editor>
|
|
458
|
+
|
|
459
|
+
<script>
|
|
460
|
+
document.getElementById('editor').addEventListener('policy-created', (e) => {
|
|
461
|
+
// e.detail.persisted === false — the PAP has not stored anything
|
|
462
|
+
console.log('Policy built:', e.detail.policy);
|
|
463
|
+
console.log('Suggested id:', e.detail.id); // the policy's odrl:uid
|
|
464
|
+
myOwnBackend.save(e.detail.policy);
|
|
465
|
+
});
|
|
466
|
+
</script>
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
Because listener code is identical in both modes, switching between them is a
|
|
470
|
+
single attribute change — check `detail.persisted` if the host needs to tell
|
|
471
|
+
them apart.
|
|
472
|
+
|
|
473
|
+
**What emit-only mode changes**
|
|
474
|
+
|
|
475
|
+
| Behaviour | `persist` (default) | `persist="false"` |
|
|
476
|
+
|-----------|---------------------|-------------------|
|
|
477
|
+
| Save button | `PUT /policy/{id}` (or the service-scoped variant), then event | event only |
|
|
478
|
+
| Create from template | stores, then event | event only |
|
|
479
|
+
| `detail.persisted` | `true` | `false` |
|
|
480
|
+
| Template management tab | visible (unless hidden) | always hidden — it can only write to the PAP |
|
|
481
|
+
|
|
482
|
+
**What it does not change** — emit-only only suppresses *writes*. The
|
|
483
|
+
component still needs a reachable PAP for read-only calls:
|
|
484
|
+
|
|
485
|
+
- `GET /mappings` — **required**; the visual builder's vocabulary dropdowns
|
|
486
|
+
are built from it.
|
|
487
|
+
- `GET /policy/{id}` — when `mode="edit"`, to load the policy being edited.
|
|
488
|
+
- `POST /validate` — only when the user runs a validation.
|
|
489
|
+
- `GET /templates` — to populate the template picker (hide it with
|
|
490
|
+
`hide-template-tab` if unwanted).
|
|
491
|
+
|
|
492
|
+
A policy emitted this way carries an `odrl:uid` (generated if the user did not
|
|
493
|
+
set one) and `detail.id` mirrors it, so the host can store the policy under a
|
|
494
|
+
stable identifier.
|
|
495
|
+
|
|
442
496
|
### Full Embedding Example
|
|
443
497
|
|
|
444
498
|
A complete working example is available at `examples/embed-example.html`. To run
|
|
@@ -55,10 +55,19 @@ export interface TabVisibility {
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
export interface EmbeddedEventMap {
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Fired after a new policy has been accepted by the editor.
|
|
60
|
+
*
|
|
61
|
+
* `persisted` is `true` when the policy was written to the PAP and `false`
|
|
62
|
+
* in emit-only mode (`persist="false"`), where storing it is up to the host.
|
|
63
|
+
*/
|
|
64
|
+
'policy-created': { policy: Record<string, unknown>; id: string; persisted: boolean };
|
|
65
|
+
/**
|
|
66
|
+
* Fired after an existing policy has been updated in the editor.
|
|
67
|
+
*
|
|
68
|
+
* See `policy-created` for the meaning of `persisted`.
|
|
69
|
+
*/
|
|
70
|
+
'policy-updated': { policy: Record<string, unknown>; id: string; persisted: boolean };
|
|
62
71
|
/** Fired after a policy validation completes. */
|
|
63
72
|
'policy-validated': { result: Record<string, unknown> };
|
|
64
73
|
/** Fired when the user clicks Cancel. */
|
|
@@ -117,6 +126,18 @@ export interface EmbeddedConfig {
|
|
|
117
126
|
* Defaults to all tabs visible.
|
|
118
127
|
*/
|
|
119
128
|
hiddenTabs: TabVisibility;
|
|
129
|
+
/**
|
|
130
|
+
* Whether saving a policy writes it to the PAP.
|
|
131
|
+
*
|
|
132
|
+
* `true` (the default) stores the policy through the policy API and then
|
|
133
|
+
* emits `policy-created` / `policy-updated` with `persisted: true`.
|
|
134
|
+
*
|
|
135
|
+
* `false` issues no write request at all: the same events carry the fully
|
|
136
|
+
* built ODRL policy with `persisted: false`, and storing it is left to the
|
|
137
|
+
* host. Read-only calls (loading a policy for editing, `/mappings`,
|
|
138
|
+
* `/validate`) are unaffected.
|
|
139
|
+
*/
|
|
140
|
+
persist: boolean;
|
|
120
141
|
}
|
|
121
142
|
|
|
122
143
|
// ---------------------------------------------------------------------------
|
|
@@ -141,6 +162,7 @@ export const TAG_NAME: 'odrl-policy-editor';
|
|
|
141
162
|
* | `locale` | Language code (e.g., `"en"`, `"de"`) | `"en"` |
|
|
142
163
|
* | `policy-context` | JSON-LD `@context` for new policies (JSON) | `null` |
|
|
143
164
|
* | `service-id` | Service ID for service-scoped policy ops | `null` |
|
|
165
|
+
* | `persist` | Boolean — `"false"` emits the policy without storing it | `true` |
|
|
144
166
|
* | `hide-builder-tab` | Boolean — hides the visual policy builder tab | absent |
|
|
145
167
|
* | `hide-raw-tab` | Boolean — hides the raw ODRL JSON editor tab | absent |
|
|
146
168
|
* | `hide-template-tab` | Boolean — hides the template selection tab | absent |
|
|
@@ -156,10 +178,10 @@ export const TAG_NAME: 'odrl-policy-editor';
|
|
|
156
178
|
*
|
|
157
179
|
* ## Custom Events
|
|
158
180
|
*
|
|
159
|
-
* | Event | Detail
|
|
160
|
-
*
|
|
161
|
-
* | `policy-created` | `{ policy: object, id: string }`
|
|
162
|
-
* | `policy-updated` | `{ policy: object, id: string }`
|
|
181
|
+
* | Event | Detail |
|
|
182
|
+
* |--------------------|---------------------------------------------------------|
|
|
183
|
+
* | `policy-created` | `{ policy: object, id: string, persisted: boolean }` |
|
|
184
|
+
* | `policy-updated` | `{ policy: object, id: string, persisted: boolean }` |
|
|
163
185
|
* | `policy-validated` | `{ result: object }` |
|
|
164
186
|
* | `editor-cancelled` | `{}` |
|
|
165
187
|
* | `template-created` | `{ template: object, id: string }` |
|